Skip to content

Commit ebbc42a

Browse files
committed
fix(trigger): use reactions.get API to fetch message text for thread replies
1 parent c9d9b42 commit ebbc42a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

apps/sim/lib/webhooks/utils.server.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,10 @@ async function downloadSlackFiles(
682682
const SLACK_REACTION_EVENTS = new Set(['reaction_added', 'reaction_removed'])
683683

684684
/**
685-
* Fetches the text of a message from Slack using conversations.history.
686-
* Requires the bot token to have channels:history (public) or groups:history (private) scope.
685+
* Fetches the text of a reacted-to message from Slack using the reactions.get API.
686+
* Unlike conversations.history, reactions.get works for both top-level messages and
687+
* thread replies, since it looks up the item directly by channel + timestamp.
688+
* Requires the bot token to have the reactions:read scope.
687689
*/
688690
async function fetchSlackMessageText(
689691
channel: string,
@@ -693,31 +695,29 @@ async function fetchSlackMessageText(
693695
try {
694696
const params = new URLSearchParams({
695697
channel,
696-
oldest: messageTs,
697-
latest: messageTs,
698-
inclusive: 'true',
699-
limit: '1',
698+
timestamp: messageTs,
700699
})
701-
const response = await fetch(`https://slack.com/api/conversations.history?${params}`, {
700+
const response = await fetch(`https://slack.com/api/reactions.get?${params}`, {
702701
headers: { Authorization: `Bearer ${botToken}` },
703702
})
704703

705704
const data = (await response.json()) as {
706705
ok: boolean
707706
error?: string
708-
messages?: Array<{ text?: string }>
707+
type?: string
708+
message?: { text?: string }
709709
}
710710

711711
if (!data.ok) {
712-
logger.warn('Slack conversations.history failed — message text unavailable', {
712+
logger.warn('Slack reactions.get failed — message text unavailable', {
713713
channel,
714714
messageTs,
715715
error: data.error,
716716
})
717717
return ''
718718
}
719719

720-
return data.messages?.[0]?.text ?? ''
720+
return data.message?.text ?? ''
721721
} catch (error) {
722722
logger.warn('Error fetching Slack message text', {
723723
channel,

apps/sim/triggers/slack/webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const slackWebhookTrigger: TriggerConfig = {
6767
'Go to <a href="https://api.slack.com/apps" target="_blank" rel="noopener noreferrer" class="text-muted-foreground underline transition-colors hover:text-muted-foreground/80">Slack Apps page</a>',
6868
'If you don\'t have an app:<br><ul class="mt-1 ml-5 list-disc"><li>Create an app from scratch</li><li>Give it a name and select your workspace</li></ul>',
6969
'Go to "Basic Information", find the "Signing Secret", and paste it in the field above.',
70-
'Go to "OAuth & Permissions" and add bot token scopes:<br><ul class="mt-1 ml-5 list-disc"><li><code>app_mentions:read</code> - For viewing messages that tag your bot with an @</li><li><code>chat:write</code> - To send messages to channels your bot is a part of</li><li><code>files:read</code> - To access files and images shared in messages</li><li><code>reactions:read</code> - For listening to emoji reactions on messages</li><li><code>channels:history</code> - To read message text when a reaction event fires (public channels)</li><li><code>groups:history</code> - To read message text when a reaction event fires (private channels)</li></ul>',
70+
'Go to "OAuth & Permissions" and add bot token scopes:<br><ul class="mt-1 ml-5 list-disc"><li><code>app_mentions:read</code> - For viewing messages that tag your bot with an @</li><li><code>chat:write</code> - To send messages to channels your bot is a part of</li><li><code>files:read</code> - To access files and images shared in messages</li><li><code>reactions:read</code> - For listening to emoji reactions and fetching reacted-to message text</li></ul>',
7171
'Go to "Event Subscriptions":<br><ul class="mt-1 ml-5 list-disc"><li>Enable events</li><li>Under "Subscribe to Bot Events", add <code>app_mention</code> to listen to messages that mention your bot</li><li>For reaction events, also add <code>reaction_added</code> and/or <code>reaction_removed</code></li><li>Paste the Webhook URL above into the "Request URL" field</li></ul>',
7272
'Go to "Install App" in the left sidebar and install the app into your desired Slack workspace and channel.',
7373
'Copy the "Bot User OAuth Token" (starts with <code>xoxb-</code>) and paste it in the Bot Token field above to enable file downloads.',

0 commit comments

Comments
 (0)