From 38e2362be667594b3e2408352a4673ab2104fc6f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 10 Jan 2026 02:11:51 +0100 Subject: [PATCH] fix: remove ack reactions after reply (#633) (thanks @levifig) --- CHANGELOG.md | 1 + docs/gateway/configuration.md | 6 +++- docs/providers/discord.md | 3 +- docs/providers/slack.md | 3 +- docs/providers/telegram.md | 2 +- src/discord/monitor.ts | 47 +++++++++++++++---------- src/slack/monitor.ts | 54 +++++++++++++++++----------- src/telegram/bot.ts | 66 ++++++++++++++++++----------------- 8 files changed, 108 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4a3ec328..b9b120b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Providers: add Microsoft Teams provider with polling, attachments, and CLI send support. (#404) — thanks @onutc - Slack: honor reply tags + replyToMode while keeping threaded replies in-thread. (#574) — thanks @bolismauro - Slack: configurable reply threading (`slack.replyToMode`) + proper mrkdwn formatting for outbound messages. (#464) — thanks @austinm911 +- Providers: remove ack reactions after reply on Discord/Slack/Telegram. (#633) — thanks @levifig - Discord: avoid category parent overrides for channel allowlists and refactor thread context helpers. (#588) — thanks @steipete - Discord: fix forum thread starters and cache channel lookups for thread context. (#585) — thanks @thewilloftheshadow - Discord: log gateway disconnect/reconnect events at info and add verbose gateway metrics. (#595) — thanks @steipete diff --git a/docs/gateway/configuration.md b/docs/gateway/configuration.md index b427da800..ccde7c27a 100644 --- a/docs/gateway/configuration.md +++ b/docs/gateway/configuration.md @@ -948,7 +948,8 @@ See [Messages](/concepts/messages) for queueing, sessions, and streaming context messages: { responsePrefix: "🦞", // or "auto" ackReaction: "👀", - ackReactionScope: "group-mentions" + ackReactionScope: "group-mentions", + removeAckAfterReply: false } } ``` @@ -975,6 +976,9 @@ active agent’s `identity.emoji` when set, otherwise `"👀"`. Set it to `""` t - `direct`: direct messages only - `all`: all messages +`removeAckAfterReply` removes the bot’s ack reaction after a reply is sent +(Slack/Discord/Telegram only). Default: `false`. + ### `talk` Defaults for Talk mode (macOS/iOS/Android). Voice IDs fall back to `ELEVENLABS_VOICE_ID` or `SAG_VOICE_ID` when unset. diff --git a/docs/providers/discord.md b/docs/providers/discord.md index a70876cbf..1ec08c00c 100644 --- a/docs/providers/discord.md +++ b/docs/providers/discord.md @@ -225,7 +225,8 @@ Outbound Discord API calls retry on rate limits (429) using Discord `retry_after ``` Ack reactions are controlled globally via `messages.ackReaction` + -`messages.ackReactionScope`. +`messages.ackReactionScope`. Use `messages.removeAckAfterReply` to clear the +ack reaction after the bot replies. - `dm.enabled`: set `false` to ignore all DMs (default `true`). - `dm.policy`: DM access control (`pairing` recommended). `"open"` requires `dm.allowFrom=["*"]`. diff --git a/docs/providers/slack.md b/docs/providers/slack.md index c95e23a0a..927030b57 100644 --- a/docs/providers/slack.md +++ b/docs/providers/slack.md @@ -192,7 +192,8 @@ Tokens can also be supplied via env vars: - `SLACK_APP_TOKEN` Ack reactions are controlled globally via `messages.ackReaction` + -`messages.ackReactionScope`. +`messages.ackReactionScope`. Use `messages.removeAckAfterReply` to clear the +ack reaction after the bot replies. ## Limits - Outbound text is chunked to `slack.textChunkLimit` (default 4000). diff --git a/docs/providers/telegram.md b/docs/providers/telegram.md index fce881f1a..f37874b27 100644 --- a/docs/providers/telegram.md +++ b/docs/providers/telegram.md @@ -287,4 +287,4 @@ Related global options: - `agents.list[].groupChat.mentionPatterns` (mention gating patterns). - `messages.groupChat.mentionPatterns` (global fallback). - `commands.native`, `commands.text`, `commands.useAccessGroups` (command behavior). -- `messages.responsePrefix`, `messages.ackReaction`, `messages.ackReactionScope`. +- `messages.responsePrefix`, `messages.ackReaction`, `messages.ackReactionScope`, `messages.removeAckAfterReply`. diff --git a/src/discord/monitor.ts b/src/discord/monitor.ts index d6276ac9d..6dffa3443 100644 --- a/src/discord/monitor.ts +++ b/src/discord/monitor.ts @@ -977,17 +977,19 @@ export function createDiscordMessageHandler(params: { } return false; }; - let didAddAckReaction = false; - if (shouldAckReaction()) { - reactMessageDiscord(message.channelId, message.id, ackReaction, { - rest: client.rest, - }).catch((err) => { - logVerbose( - `discord react failed for channel ${message.channelId}: ${String(err)}`, - ); - }); - didAddAckReaction = true; - } + const ackReactionPromise = shouldAckReaction() + ? reactMessageDiscord(message.channelId, message.id, ackReaction, { + rest: client.rest, + }).then( + () => true, + (err) => { + logVerbose( + `discord react failed for channel ${message.channelId}: ${String(err)}`, + ); + return false; + }, + ) + : null; const fromLabel = isDirectMessage ? buildDirectLabel(author) @@ -1208,13 +1210,22 @@ export function createDiscordMessageHandler(params: { `discord: delivered ${finalCount} reply${finalCount === 1 ? "" : "ies"} to ${replyTarget}`, ); } - if (removeAckAfterReply && didAddAckReaction && ackReaction) { - removeReactionDiscord(message.channelId, message.id, ackReaction, { - rest: client.rest, - }).catch((err) => { - logVerbose( - `discord: failed to remove ack reaction from ${message.channelId}/${message.id}: ${String(err)}`, - ); + if (removeAckAfterReply && ackReactionPromise && ackReaction) { + const ackReactionValue = ackReaction; + void ackReactionPromise.then((didAck) => { + if (!didAck) return; + removeReactionDiscord( + message.channelId, + message.id, + ackReactionValue, + { + rest: client.rest, + }, + ).catch((err) => { + logVerbose( + `discord: failed to remove ack reaction from ${message.channelId}/${message.id}: ${String(err)}`, + ); + }); }); } if ( diff --git a/src/slack/monitor.ts b/src/slack/monitor.ts index 9589856a6..d95443b3c 100644 --- a/src/slack/monitor.ts +++ b/src/slack/monitor.ts @@ -913,6 +913,7 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) { const rawBody = (message.text ?? "").trim() || media?.placeholder || ""; if (!rawBody) return; const ackReaction = resolveAckReaction(cfg, route.agentId); + const ackReactionValue = ackReaction ?? ""; const removeAckAfterReply = cfg.messages?.removeAckAfterReply ?? false; const shouldAckReaction = () => { if (!ackReaction) return false; @@ -928,18 +929,27 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) { } return false; }; - let didAddAckReaction = false; - if (shouldAckReaction() && message.ts) { - reactSlackMessage(message.channel, message.ts, ackReaction, { - token: botToken, - client: app.client, - }).catch((err) => { - logVerbose( - `slack react failed for channel ${message.channel}: ${String(err)}`, - ); - }); - didAddAckReaction = true; - } + const ackReactionMessageTs = message.ts; + const ackReactionPromise = + shouldAckReaction() && ackReactionMessageTs && ackReactionValue + ? reactSlackMessage( + message.channel, + ackReactionMessageTs, + ackReactionValue, + { + token: botToken, + client: app.client, + }, + ).then( + () => true, + (err) => { + logVerbose( + `slack react failed for channel ${message.channel}: ${String(err)}`, + ); + return false; + }, + ) + : null; const roomLabel = channelName ? `#${channelName}` : `#${message.channel}`; @@ -1160,14 +1170,18 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) { `slack: delivered ${finalCount} reply${finalCount === 1 ? "" : "ies"} to ${replyTarget}`, ); } - if (removeAckAfterReply && didAddAckReaction && ackReaction && message.ts) { - removeSlackReaction(message.channel, message.ts, ackReaction, { - token: botToken, - client: app.client, - }).catch((err) => { - logVerbose( - `slack: failed to remove ack reaction from ${message.channel}/${message.ts}: ${String(err)}`, - ); + if (removeAckAfterReply && ackReactionPromise && ackReactionMessageTs) { + const messageTs = ackReactionMessageTs; + void ackReactionPromise.then((didAck) => { + if (!didAck) return; + removeSlackReaction(message.channel, messageTs, ackReactionValue, { + token: botToken, + client: app.client, + }).catch((err) => { + logVerbose( + `slack: failed to remove ack reaction from ${message.channel}/${message.ts}: ${String(err)}`, + ); + }); }); } }; diff --git a/src/telegram/bot.ts b/src/telegram/bot.ts index 5631330a0..1a3f84b8d 100644 --- a/src/telegram/bot.ts +++ b/src/telegram/bot.ts @@ -591,28 +591,31 @@ export function createTelegramBot(opts: TelegramBotOptions) { } return false; }; - let didAddAckReaction = false; - if (shouldAckReaction() && msg.message_id) { - const api = bot.api as unknown as { - setMessageReaction?: ( - chatId: number | string, - messageId: number, - reactions: Array<{ type: "emoji"; emoji: string }>, - ) => Promise; - }; - if (typeof api.setMessageReaction === "function") { - api - .setMessageReaction(chatId, msg.message_id, [ + const api = bot.api as unknown as { + setMessageReaction?: ( + chatId: number | string, + messageId: number, + reactions: Array<{ type: "emoji"; emoji: string }>, + ) => Promise; + }; + const reactionApi = + typeof api.setMessageReaction === "function" + ? api.setMessageReaction.bind(api) + : null; + const ackReactionPromise = + shouldAckReaction() && msg.message_id && reactionApi + ? reactionApi(chatId, msg.message_id, [ { type: "emoji", emoji: ackReaction }, - ]) - .catch((err) => { - logVerbose( - `telegram react failed for chat ${chatId}: ${String(err)}`, - ); - }); - didAddAckReaction = true; - } - } + ]).then( + () => true, + (err) => { + logVerbose( + `telegram react failed for chat ${chatId}: ${String(err)}`, + ); + return false; + }, + ) + : null; let placeholder = ""; if (msg.photo) placeholder = ""; @@ -857,21 +860,20 @@ export function createTelegramBot(opts: TelegramBotOptions) { markDispatchIdle(); draftStream?.stop(); if (!queuedFinal) return; - if (removeAckAfterReply && didAddAckReaction && msg.message_id) { - const api = bot.api as unknown as { - setMessageReaction?: ( - chatId: number | string, - messageId: number, - reactions: Array<{ type: "emoji"; emoji: string }>, - ) => Promise; - }; - if (typeof api.setMessageReaction === "function") { - api.setMessageReaction(chatId, msg.message_id, []).catch((err) => { + if ( + removeAckAfterReply && + ackReactionPromise && + msg.message_id && + reactionApi + ) { + void ackReactionPromise.then((didAck) => { + if (!didAck) return; + reactionApi(chatId, msg.message_id, []).catch((err) => { logVerbose( `telegram: failed to remove ack reaction from ${chatId}/${msg.message_id}: ${String(err)}`, ); }); - } + }); } };