Skip to content

Commit 43fc86c

Browse files
committed
chore: Reactions in slack should me permanent
1 parent 4172357 commit 43fc86c

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

server/clients/slack/bot.go

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (c *Client) handleAppMention(event slackevents.EventsAPIEvent) {
164164
threadTS = ev.TimeStamp
165165
}
166166

167-
if c.handleBotCommand(ev.User, ev.Channel, text) {
167+
if c.handleBotCommand(ev.User, ev.Channel, text, threadTS) {
168168
return
169169
}
170170

@@ -200,12 +200,12 @@ func (c *Client) handleMessage(event slackevents.EventsAPIEvent) {
200200
return
201201
}
202202

203-
if c.handleBotCommand(ev.User, ev.Channel, text) {
203+
threadTS := ev.ThreadTimeStamp
204+
205+
if c.handleBotCommand(ev.User, ev.Channel, text, threadTS) {
204206
return
205207
}
206208

207-
threadTS := ev.ThreadTimeStamp
208-
209209
c.logger.Info("Slack DM received", "user", ev.User, "channel", ev.Channel, "text", text)
210210
c.processMessage(ev.User, ev.Channel, "im", text, threadTS, ev.TimeStamp, event.TeamID, false)
211211
}
@@ -288,7 +288,7 @@ func (c *Client) handleAudioClip(ev *slackevents.MessageEvent, teamID string) bo
288288
return false
289289
}
290290

291-
func (c *Client) handleBotCommand(userID, channelID, text string) bool {
291+
func (c *Client) handleBotCommand(userID, channelID, text, threadTS string) bool {
292292
lower := strings.ToLower(strings.TrimSpace(text))
293293

294294
if !strings.HasPrefix(lower, "!") {
@@ -305,7 +305,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
305305
"• `!reset` — Reset the conversation session\n" +
306306
"• `!responsemode` — Show or change the response mode\n" +
307307
"• `!responsemode <mode>` — Set response mode (`text`, `voice`, `mirror`, `both`, `reset`)"
308-
c.postMessage(channelID, helpText, "")
308+
c.postMessage(channelID, helpText, threadTS)
309309
return true
310310
}
311311

@@ -329,7 +329,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
329329
agentList += fmt.Sprintf("%s%s\n", marker, label)
330330
}
331331
msg := fmt.Sprintf("*Active agent:* %s\n\n*Available agents:*\n%s\nUsage: `!agent <id>`", currentLabel, agentList)
332-
c.postMessage(channelID, msg, "")
332+
c.postMessage(channelID, msg, threadTS)
333333
return true
334334
}
335335

@@ -347,7 +347,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
347347
for _, a := range c.agents {
348348
ids = append(ids, "`"+a.ID+"`")
349349
}
350-
c.postMessage(channelID, fmt.Sprintf("Unknown agent `%s`. Available: %s", agentID, strings.Join(ids, ", ")), "")
350+
c.postMessage(channelID, fmt.Sprintf("Unknown agent `%s`. Available: %s", agentID, strings.Join(ids, ", ")), threadTS)
351351
return true
352352
}
353353
c.setActiveAgentID(channelID, agentID)
@@ -357,7 +357,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
357357
label = agent.Name
358358
}
359359
c.logger.Info("Slack agent switched", "channel", channelID, "agent", agentID)
360-
c.postMessage(channelID, fmt.Sprintf("Switched to agent *%s* (`%s`)", label, agentID), "")
360+
c.postMessage(channelID, fmt.Sprintf("Switched to agent *%s* (`%s`)", label, agentID), threadTS)
361361
return true
362362
}
363363

@@ -373,7 +373,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
373373
}
374374
status += "\n*Options:* `text`, `voice`, `mirror`, `both`, `reset`"
375375

376-
c.postMessage(channelID, status, "")
376+
c.postMessage(channelID, status, threadTS)
377377
return true
378378
}
379379

@@ -382,7 +382,7 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
382382
sessionID := c.buildSessionID(channelID, "")
383383
if err := c.deleteSession(agentID, sessionID); err != nil {
384384
c.logger.Error("Failed to delete session", "error", err)
385-
c.postMessage(channelID, "Failed to reset session.", "")
385+
c.postMessage(channelID, "Failed to reset session.", threadTS)
386386
return true
387387
}
388388
c.logger.Info("Session reset", "channel", channelID, "agent", agentID, "session", sessionID)
@@ -391,19 +391,19 @@ func (c *Client) handleBotCommand(userID, channelID, text string) bool {
391391
if agent != nil && agent.Name != "" {
392392
label = agent.Name
393393
}
394-
c.postMessage(channelID, fmt.Sprintf("Session reset for *%s*. Next message starts a fresh conversation.", label), "")
394+
c.postMessage(channelID, fmt.Sprintf("Session reset for *%s*. Next message starts a fresh conversation.", label), threadTS)
395395
return true
396396
}
397397

398398
if strings.HasPrefix(lower, "responsemode ") {
399399
arg := strings.TrimSpace(text[13:])
400-
return c.handleResponseModeCommand(channelID, arg)
400+
return c.handleResponseModeCommand(channelID, arg, threadTS)
401401
}
402402

403403
return false
404404
}
405405

406-
func (c *Client) handleResponseModeCommand(channelID, arg string) bool {
406+
func (c *Client) handleResponseModeCommand(channelID, arg, threadTS string) bool {
407407
validModes := []string{ResponseModeText, ResponseModeVoice, ResponseModeMirror, ResponseModeBoth}
408408

409409
if arg == "reset" {
@@ -413,12 +413,12 @@ func (c *Client) handleResponseModeCommand(channelID, arg string) bool {
413413
c.logger.Info("Response mode override cleared",
414414
"config_mode", c.clientDef.Config.Slack.ResponseMode,
415415
)
416-
c.postMessage(channelID, fmt.Sprintf("Response mode reset to config default: `%s`", c.clientDef.Config.Slack.ResponseMode), "")
416+
c.postMessage(channelID, fmt.Sprintf("Response mode reset to config default: `%s`", c.clientDef.Config.Slack.ResponseMode), threadTS)
417417
return true
418418
}
419419

420420
if !slices.Contains(validModes, arg) {
421-
c.postMessage(channelID, fmt.Sprintf("Invalid mode `%s`. Valid options: `text`, `voice`, `mirror`, `both`, `reset`", arg), "")
421+
c.postMessage(channelID, fmt.Sprintf("Invalid mode `%s`. Valid options: `text`, `voice`, `mirror`, `both`, `reset`", arg), threadTS)
422422
return true
423423
}
424424

@@ -427,7 +427,7 @@ func (c *Client) handleResponseModeCommand(channelID, arg string) bool {
427427
c.responseMu.Unlock()
428428

429429
c.logger.Info("Response mode overridden", "new_mode", arg)
430-
c.postMessage(channelID, fmt.Sprintf("Response mode set to `%s` (until restart)", arg), "")
430+
c.postMessage(channelID, fmt.Sprintf("Response mode set to `%s` (until restart)", arg), threadTS)
431431
return true
432432
}
433433

@@ -828,18 +828,7 @@ func (c *Client) addReaction(emoji string, ref slackapi.ItemRef) {
828828
}
829829
}
830830

831-
func (c *Client) removeReaction(emoji string, ref slackapi.ItemRef) {
832-
if err := c.api.RemoveReaction(emoji, ref); err != nil {
833-
c.logger.Debug("Failed to remove reaction", "emoji", emoji, "error", err)
834-
}
835-
}
836-
837831
func (c *Client) setReaction(emoji string, ref slackapi.ItemRef) {
838-
for _, old := range []string{"eyes", "brain", "white_check_mark", "x"} {
839-
if old != emoji {
840-
c.removeReaction(old, ref)
841-
}
842-
}
843832
c.addReaction(emoji, ref)
844833
}
845834

0 commit comments

Comments
 (0)