From 4c02642d0e19ff437573c31742a9c1783e7b6f56 Mon Sep 17 00:00:00 2001 From: kathiouchka Date: Fri, 28 Jun 2024 21:35:05 +0200 Subject: [PATCH] feat: slacker now handles unfurling option + main.go for testing purpose --- examples/message-unfurl/main.go | 39 +++++++++++++++++++++++++++++++++ response_writer.go | 4 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 examples/message-unfurl/main.go diff --git a/examples/message-unfurl/main.go b/examples/message-unfurl/main.go new file mode 100644 index 0000000..cf6f5c2 --- /dev/null +++ b/examples/message-unfurl/main.go @@ -0,0 +1,39 @@ +// main.go + +package main + +import ( + "context" + "log" + "os" + + "github.com/slack-io/slacker" +) + +// Defining commands using slacker + +func main() { + bot := slacker.NewClient(os.Getenv("SLACK_BOT_TOKEN"), os.Getenv("SLACK_APP_TOKEN")) + + bot.AddCommand(&slacker.CommandDefinition{ + Command: "without", + Handler: func(ctx *slacker.CommandContext) { + ctx.Response().Reply("https://signoz.io/", slacker.WithUnfurlLinks(false)) + }, + }) + + bot.AddCommand(&slacker.CommandDefinition{ + Command: "with", + Handler: func(ctx *slacker.CommandContext) { + ctx.Response().Reply("https://signoz.io/") + }, + }) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + err := bot.Listen(ctx) + if err != nil { + log.Fatal(err) + } +} diff --git a/response_writer.go b/response_writer.go index 9983b87..7e7f33c 100644 --- a/response_writer.go +++ b/response_writer.go @@ -77,10 +77,10 @@ func (r *Writer) post(channel string, message string, blocks []slack.Block, opti opts = append(opts, slack.MsgOptionSchedule(postAt)) } + // response_writer.go if postOptions.UnfurlLinks != nil { if !*postOptions.UnfurlLinks { - opts = append(opts, slack.MsgOptionDisableLinkUnfurl()) - fmt.Println("unfurls are disabled") + opts = append(opts, slack.MsgOptionDisableLinkUnfurl(), slack.MsgOptionDisableMediaUnfurl()) } }