feat(slack): refetch unfurl attachments for inbound messages with URLs#415
feat(slack): refetch unfurl attachments for inbound messages with URLs#415sentry-junior[bot] wants to merge 1 commit into
Conversation
Slack delivers unfurl previews asynchronously — the initial message event arrives with empty `attachments`, and the actual unfurl data comes later via a `message_changed` event. The existing `message_changed` handler only triggers on newly-added bot mentions, so unfurl data was silently dropped. Add `maybeRefetchSlackUnfurlAttachments` in `slack/unfurl-fetch.ts` that, when the inbound `message.raw` has no attachment data but the message text contains a URL, retries `conversations.replies` with short delays (400 ms, 800 ms, 1.3 s) to give Slack time to generate the preview. On success, the fetched `attachments` are merged back into the raw object so that the existing `appendSlackLegacyAttachmentText` path renders them into the user turn text as normal `[attachment] ...` lines. The call is gated on: missing raw attachments AND a URL in the text AND known channel/message identifiers — so messages without URLs incur no extra API call. Co-authored-by: Sergiy Dybskiy <sergiy@sentry.io> Co-authored-by: claude-opus-4-5 <noreply>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I'm not really sure this is a good idea. Whats the issue? Having arbitrary "try to process the message again" delays is going to cause all sorts of problems. |
|
@dcramer we have the gibpotato app that unfurls discord links and adds content as attachments. for some reason even when the message preview before sending already includes the unfurled content preview of the attachments, junior fails to see them when posted. beyond discord unfurl in our usecase, i feel like theres other usecases where this async attachment context might be helpful? i could be wrong and this could be not the right solution to a problem (or not big enough of a problem to solve for) Context thread on slack: https://sentry.slack.com/archives/C0B2KJG9B5Z/p1779722822970109 |
Fixes #416
Problem
Slack generates link unfurl previews asynchronously. The initial
messageevent arrives with an emptyattachmentsarray; the actual unfurl data lands later via amessage_changedevent. The existingmessage_changedhandler only fires for newly-added bot mentions, so unfurl data was silently dropped and Junior never saw it — even when the preview was visible in the Slack UI.Fix
Add
maybeRefetchSlackUnfurlAttachments(slack/unfurl-fetch.ts) called inreply-executor.tsbeforeprepareTurnStatefinalises the user turn text.When the inbound
message.rawhas no attachment data and the text contains a URL, the helper retriesconversations.replieswith short delays (400 ms → 800 ms → 1.3 s). On a match, fetchedattachmentsare merged back into the raw object so the existingappendSlackLegacyAttachmentTextpath renders them as normal[attachment] …lines. The call is a no-op for messages without URLs.Verification
pnpm typecheckclean.Action taken on behalf of Sergiy Dybskiy.