-
Notifications
You must be signed in to change notification settings - Fork 150
Attachment fetchData lost after debounce/queue serialization #323
Description
Bug Description
When using the debounce or queue concurrency strategy, Attachment.fetchData closures are lost during message serialization. enqueue
calls JSON.stringify(entry) which strips functions. After rehydrateMessage, all attachments have fetchData: undefined — handlers cannot
download files/images.
Steps to Reproduce
- Create a Chat instance with
concurrency: { strategy: 'debounce', debounceMs: 2000 } - Register an
onSubscribedMessagehandler that accessesmessage.attachments[0].fetchData - Send a message with an image attachment from Slack
- Message enters handleQueueOrDebounce → enqueue → JSON.stringify strips fetchData
- After debounce delay, dequeue → rehydrateMessage → attachments[].fetchData is undefined
- Handler throws: TypeError: fetchData is not a function
Expected Behavior
After dequeue + rehydrate, attachment.fetchData should be a working function. The attachment's url, name, mimeType survive serialization — only
fetchData (a closure) is lost. rehydrateMessage should recreate fetchData from the adapter using att.url.
Actual Behavior
attachment.fetchData is undefined after rehydration. All file/image downloads fail for debounced messages. Works correctly with 'drop' and
'concurrent' strategies (no serialization).
Code Sample
import { Chat } from 'chat';
import { SlackAdapter } from '@chat-adapter/slack';
const chat = new Chat({
adapters: [new SlackAdapter({ botToken: '...' })],
concurrency: { strategy: 'debounce', debounceMs: 2000 },
});
chat.onSubscribedMessage(async (thread, message) => {
const att = message.attachments.find(a => a.type === 'image');
if (att) {
console.log(att.url); // ✅ "https://files.slack.com/..." (survives serialization)
console.log(att.fetchData); // ❌ undefined (closure lost after JSON.stringify)
await att.fetchData(); // 💥 TypeError: fetchData is not a function
}
});Chat SDK Version
latest
Node.js Version
4.23.0
Platform Adapter
No response
Operating System
None
Additional Context
No response