Skip to content

Commit

Permalink
Merge pull request BeepBoopHQ#4 from adampointer/threads
Browse files Browse the repository at this point in the history
Fix replies in existing threads
  • Loading branch information
adampointer authored Nov 27, 2017
2 parents 3479eb0 + 8e30309 commit b350918
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 6 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ func (b *Bot) ReplyWithAttachments(evt *slack.MessageEvent, attachments []slack.
// ReplyAsThread
func (b *Bot) ReplyInThread(evt *slack.MessageEvent, msg string, typing bool) {
params := slack.PostMessageParameters{AsUser: true}
params.ThreadTimestamp = evt.Timestamp

if evt.ThreadTimestamp == "" {
params.ThreadTimestamp = evt.Timestamp
} else {
params.ThreadTimestamp = evt.ThreadTimestamp
}

b.Client.PostMessage(evt.Msg.Channel, msg, params)
}
Expand Down
5 changes: 2 additions & 3 deletions examples/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ func main() {
toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter()
toMe.Hear("(?i)(hi|hello).*").MessageHandler(HelloHandler)
bot.Hear("(?i)how are you(.*)").MessageHandler(HowAreYouHandler)
bot.Hear("(?)attachment").MessageHandler(AttachmentsHandler)
bot.Run()
}

func HelloHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
bot.Reply(evt, "Oh hello!", slackbot.WithTyping)
bot.ReplyInThread(evt, "Oh hello!", slackbot.WithTyping)
}

func HowAreYouHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
bot.Reply(evt, "A bit tired. You get it? A bit?", slackbot.WithTyping)
bot.ReplyInThread(evt, "A bit tired. You get it? A bit?", slackbot.WithTyping)
}

func AttachmentsHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
Expand Down

0 comments on commit b350918

Please sign in to comment.