feat(think): add Discord interactions messenger#1787
Conversation
🦋 Changeset detectedLatest commit: 5093e03 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
| this.runInteractionTask(options, async () => { | ||
| await this.storeInteractionResponseContext(surfaceId, { | ||
| channelId, | ||
| expiresAt: Date.now() + DISCORD_INTERACTION_TOKEN_TTL_MS, | ||
| initialResponseSent: false, | ||
| token: interaction.token | ||
| }); | ||
|
|
||
| chat.processSlashCommand( | ||
| { | ||
| adapter: this, | ||
| channelId: surfaceId, | ||
| command, | ||
| raw: redactDiscordInteraction(interaction), | ||
| text, | ||
| user: toDiscordAuthor(user) | ||
| }, | ||
| options | ||
| ); | ||
| }); |
There was a problem hiding this comment.
🚩 processSlashCommand and processAction are not awaited inside background tasks
In handleApplicationCommand (line 376) and handleMessageComponent (line 418), chat.processSlashCommand(...) and chat.processAction(...) are called without await inside the async callback passed to runInteractionTask. This means: (1) synchronous throws are caught by the async function and propagate to .catch(), (2) but if these Chat SDK methods return rejected promises, those rejections would be unhandled since the async function resolves before the returned promise settles. This is likely intentional — the Chat SDK's processSlashCommand/processAction appear to be synchronous event dispatchers — but if the Chat SDK ever changes to return promises, unhandled rejections could surface. The pattern is consistent with the design goal of responding to Discord within 3 seconds.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Adds Discord slash-command support for Think agents.
Out of the box, a Think agent can now be connected to a Discord application Interactions endpoint and answer Discord slash commands from an HTTP callback, without discord.js or Node-only runtime dependencies.
For example, after configuring a Discord application endpoint, users can type a slash command like
/ask summarize this incidentin Discord. Think verifies the Discord signature, acknowledges the interaction, routes the command into the agent as a messenger turn, and sends the agent reply back through Discord interaction response webhooks.This also supports Discord button and select interactions as inbound action events, so interactions attached to Discord messages can be routed back into the same Think conversation flow.
What Works Now
PING.discord.js.What Users Still Need To Do
Not Included Yet
Verification
pnpm --filter @cloudflare/think exec vitest --run -c src/tests/vitest.config.ts src/tests/messengers.test.ts --reporter=dotpnpm --filter @cloudflare/think run buildpnpm run check