Skip to content

feat(think): add Discord interactions messenger#1787

Open
dcartertwo wants to merge 1 commit into
feature/discord-messengersfrom
feature/discord-provider-implementation
Open

feat(think): add Discord interactions messenger#1787
dcartertwo wants to merge 1 commit into
feature/discord-messengersfrom
feature/discord-provider-implementation

Conversation

@dcartertwo

@dcartertwo dcartertwo commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

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 incident in 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

  • Discord can verify the Worker as an Interactions endpoint with PING.
  • Discord slash commands can start Think messenger turns.
  • Discord button and select component interactions can start Think action turns.
  • Agent replies to slash commands and actions are delivered through Discord interaction webhooks.
  • Discord interaction tokens are redacted from persisted messenger metadata.
  • Multiple Discord messenger definitions can use distinct adapter names.
  • The implementation runs on Workers without discord.js.

What Users Still Need To Do

  • Create a Discord application.
  • Configure the Interactions Endpoint URL to the Worker messenger path.
  • Register slash commands with Discord.
  • Store the Discord public key and application ID in Worker config or secrets.

Not Included Yet

  • Reading normal Discord messages, DMs, or mentions.
  • Gateway/WebSocket support.
  • Posting to Discord channels outside the interaction response window.
  • Command registration helpers.
  • Attachments.
  • Rich Discord component/card rendering.
  • Reactions/edit/delete/fetch APIs.

Verification

  • pnpm --filter @cloudflare/think exec vitest --run -c src/tests/vitest.config.ts src/tests/messengers.test.ts --reporter=dot
  • pnpm --filter @cloudflare/think run build
  • pnpm run check

Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5093e03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/think Minor

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

@pkg-pr-new

pkg-pr-new Bot commented Jun 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1787

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1787

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1787

create-think

npm i https://pkg.pr.new/create-think@1787

hono-agents

npm i https://pkg.pr.new/hono-agents@1787

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1787

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1787

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1787

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1787

commit: 5093e03

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Comment on lines +368 to +387
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
);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant