making the bot listen with mentions in DMs

This commit is contained in:
ari committed 2026-11-01 14:24:32 -05:00
1 parent 650bcff83a
commit 3ba96528bb
2 files changed
+22 -3

No files matched your search

+6 -3
View File
@@ -152,13 +152,12 @@ func (b *Bot) onEvent(ctx context.Context, ev slackevents.EventsAPIEvent) {
if e.BotID != "" {
return
}
text := strings.TrimSpace(strings.ReplaceAll(e.Text, "<@"+b.botID+">", ""))
b.onMessage(ctx, incoming{e.User, e.Channel, e.TimeStamp, e.ThreadTimeStamp, text, false, false})
b.onMessage(ctx, incoming{e.User, e.Channel, e.TimeStamp, e.ThreadTimeStamp, b.stripMention(e.Text), false, false})
case *slackevents.MessageEvent:
if e.BotID != "" || e.SubType != "" || e.User == "" || e.User == b.botID {
return
}
text := strings.TrimSpace(e.Text)
text := b.stripMention(e.Text)
switch {
case e.ChannelType == "im":
b.onMessage(ctx, incoming{e.User, e.Channel, e.TimeStamp, e.ThreadTimeStamp, text, true, false})
@@ -174,6 +173,10 @@ func (b *Bot) onEvent(ctx context.Context, ev slackevents.EventsAPIEvent) {
}
}
func (b *Bot) stripMention(text string) string {
return strings.TrimSpace(strings.ReplaceAll(text, "<@"+b.botID+">", ""))
}
func (b *Bot) onMessage(ctx context.Context, m incoming) {
if b.listenCommand(ctx, m) {
return