Skip to content

Commit 89b8977

Browse files
feat(discord): add canvas-first Discord Activities support
1 parent 3704069 commit 89b8977

41 files changed

Lines changed: 1698 additions & 20 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fce3cbf24274016e01324082ad8ffe81fe2fb41a6e6314aa6efcdbe6689fd628 config-baseline.json
1+
614f0fc957a944978989de9b98429d2540e8f1b33b925a0148acd265490922ed config-baseline.json
22
fb6f0ef881fb591d2791d2adca43c7e88d48f8b562457683092ab6e767aece78 config-baseline.core.json
3-
3bb312dc9c39a374ca92613abf21606c25dc571287a3941dac71ff57b2b5c519 config-baseline.channel.json
3+
e1f94346a8507ce3dec763b598e79f3bb89ff2e33189ce977cc87d3b05e71c1d config-baseline.channel.json
44
6c19997f1fb2aff4315f2cb9c7d9e299b403fbc0f9e78e3412cc7fe1c655f222 config-baseline.plugin.json
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
summary: "Configure Discord Activities to launch the OpenClaw Canvas surface"
3+
read_when:
4+
- Discord plugin setup is already working and you want Activities
5+
- You need exact Discord Developer Portal URL mapping values
6+
title: "Discord Activities"
7+
---
8+
9+
# Discord Activities
10+
11+
Status: ready for Activity-hosted Canvas (`/__openclaw__/canvas/`).
12+
13+
This page assumes your [Discord](/channels/discord) channel setup is already complete.
14+
15+
## Public HTTPS requirement
16+
17+
Discord Activities must load from a **public HTTPS URL**.
18+
19+
Not supported for Activity launch:
20+
21+
- `http://localhost:...`
22+
- `http://192.168.x.x:...`
23+
- `http://10.x.x.x:...`
24+
- hostnames that are only reachable inside your home/LAN
25+
26+
Use an internet-reachable HTTPS host for your gateway.
27+
28+
Where this is documented elsewhere:
29+
30+
- [Tailscale (Serve and Funnel)](/gateway/tailscale)
31+
- [Web bind and security modes](/web)
32+
- [Google Chat public URL examples (Serve/Funnel + proxy patterns)](/channels/googlechat#public-url-webhook-only)
33+
34+
## Quick setup
35+
36+
<Steps>
37+
<Step title="Open your existing Discord app">
38+
Go to [Discord Developer Portal](https://discord.com/developers/applications) and open the same app you already use for OpenClaw Discord.
39+
</Step>
40+
41+
<Step title="Enable Activities">
42+
Open **Activities > Settings** and turn on **Enable Activities**.
43+
44+
Under **Supported Platforms**, enable the platforms you plan to test:
45+
46+
- Web
47+
- Desktop
48+
- iOS
49+
- Android
50+
51+
</Step>
52+
53+
<Step title="Configure URL mappings">
54+
Open **Activities > URL Mappings** and add:
55+
56+
| PREFIX | TARGET |
57+
| --- | --- |
58+
| `/` | `<your-gateway-host>/__openclaw__/canvas` |
59+
60+
Example:
61+
62+
| PREFIX | TARGET |
63+
| --- | --- |
64+
| `/` | `gateway.example.com/__openclaw__/canvas` |
65+
66+
Rules:
67+
68+
- TARGET must not include protocol.
69+
- Correct: `gateway.example.com/__openclaw__/canvas`
70+
- Wrong: `https://gateway.example.com/__openclaw__/canvas`
71+
- Keep `/` as the fallback mapping.
72+
- If you add more mappings, place longer prefixes before `/`.
73+
- Do not point `/` at gateway root alone, or Discord Activity launch will open the Control UI path instead of Canvas.
74+
75+
</Step>
76+
77+
<Step title="Enable Activity-scoped auth in OpenClaw (required)">
78+
Discord Activity iframes cannot send your normal Gateway bearer token.
79+
80+
In your OpenClaw config, set:
81+
82+
```json5
83+
{
84+
canvasHost: {
85+
activity: {
86+
enabled: true,
87+
// Optional shared token gate for activity requests.
88+
token: "<long-random-token>",
89+
// Optional override. Default is true; set false only for legacy/manual testing flows.
90+
requireLaunchContext: true,
91+
},
92+
},
93+
}
94+
```
95+
96+
This keeps normal Gateway auth in place while allowing Activity-scoped Canvas access.
97+
98+
</Step>
99+
100+
<Step title="Set Activity launch URL">
101+
Use this Activity URL:
102+
103+
- `https://<your-gateway-host>/`
104+
105+
Discord launches at `/`, and URL mapping should rewrite that path to `/__openclaw__/canvas`.
106+
107+
If `canvasHost.activity.token` is set, include `activityToken=<token>` in your mapped target or preserve it through your edge rewrite.
108+
109+
Agents can still render A2UI experiences inside Canvas when needed.
110+
111+
</Step>
112+
113+
<Step title="Optional: add a launch button in Discord messages">
114+
Discord component buttons support:
115+
116+
- `action: "launch-activity"`
117+
118+
Example:
119+
120+
```json
121+
{
122+
"label": "Open Activity",
123+
"style": "primary",
124+
"action": "launch-activity"
125+
}
126+
```
127+
128+
Notes:
129+
130+
- `launch-activity` works from guild channels.
131+
- It is not valid on link-style buttons.
132+
- In OpenClaw agent replies, prefer `message` tool helper `activityLaunchButton=true` for this action.
133+
134+
</Step>
135+
136+
<Step title="Optional: use OpenClaw Discord SDK helpers inside Canvas pages">
137+
Hosted Canvas pages auto-inject a Discord helper in Activity context:
138+
139+
- `window.OpenClaw.discord` (alias: `window.openclawDiscord`)
140+
141+
Common usage:
142+
143+
```js
144+
await OpenClaw.discord.load();
145+
await OpenClaw.discord.commands.openShareMomentDialog({ mediaUrl: "https://..." });
146+
await OpenClaw.discord.commands.openExternalLink("https://docs.openclaw.ai");
147+
148+
const auth = await OpenClaw.discord.oauth.authorize({
149+
client_id: "<discord-app-id>",
150+
response_type: "code",
151+
scope: ["identify", "guilds"],
152+
prompt: "none",
153+
state: "example-state",
154+
});
155+
// exchange auth.code on your backend, then:
156+
await OpenClaw.discord.oauth.authenticate({ access_token: "<app-access-token>" });
157+
```
158+
159+
</Step>
160+
161+
<Step title="Verify before debugging client behavior">
162+
163+
```bash
164+
curl -I "https://<your-gateway-host>/__openclaw__/canvas/"
165+
```
166+
167+
Expected:
168+
169+
- HTTP `200`
170+
- `text/html` response
171+
172+
</Step>
173+
</Steps>
174+
175+
## Troubleshooting
176+
177+
### Activity does not appear in the shelf
178+
179+
- Confirm **Enable Activities** is on.
180+
- Confirm current platform is enabled in **Supported Platforms**.
181+
- Confirm app is installed in the context you are testing (guild/user install).
182+
183+
### Activity opens but shows 404 or blank page
184+
185+
- Confirm URL mapping is `PREFIX /` -> `TARGET <gateway-host>/__openclaw__/canvas`.
186+
- Confirm TARGET has no protocol.
187+
- Confirm gateway host is publicly reachable over HTTPS.
188+
- Confirm you are not using an internal-only address.
189+
- Confirm reverse proxy preserves `/__openclaw__/canvas/` path.
190+
191+
### Launch button says Activities are unavailable
192+
193+
- Confirm interaction came from a guild channel (not DM/group DM).
194+
- Confirm Activities are enabled in the Developer Portal app.
195+
196+
### Activity opens but immediately fails auth
197+
198+
- Confirm `canvasHost.activity.enabled` is `true`.
199+
- If `canvasHost.activity.token` is set, confirm the request carries `activityToken=<token>` and the token matches exactly.
200+
- `canvasHost.activity.requireLaunchContext` is enabled by default; confirm launch context params (for example `instance_id`) are present on initial launch. Set it to `false` only if you intentionally allow direct/manual opens.
201+
202+
## Developer Portal quick links
203+
204+
- Applications: `https://discord.com/developers/applications`
205+
- Activities settings: `https://discord.com/developers/applications/<app-id>/embedded/settings`
206+
- Activities URL mappings: `https://discord.com/developers/applications/<app-id>/embedded/url-mappings`
207+
- Installation: `https://discord.com/developers/applications/<app-id>/installation`
208+
209+
## Related
210+
211+
- [Discord](/channels/discord)
212+
- [Chat Channels](/channels)
213+
- [Nodes and Canvas A2UI](/nodes)
214+
- [Tailscale](/gateway/tailscale)
215+
- [Web](/web)
216+
- Discord docs: [Activities Overview](https://docs.discord.com/developers/activities/overview)

‎docs/channels/discord.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ title: "Discord"
99

1010
Status: ready for DMs and guild channels via the official Discord gateway.
1111

12-
<CardGroup cols={3}>
12+
<CardGroup cols={4}>
1313
<Card title="Pairing" icon="link" href="/channels/pairing">
1414
Discord DMs default to pairing mode.
1515
</Card>
1616
<Card title="Slash commands" icon="terminal" href="/tools/slash-commands">
1717
Native command behavior and command catalog.
1818
</Card>
19+
<Card title="Discord Activities" icon="gamepad-2" href="/channels/discord-activities">
20+
Host OpenClaw Canvas in a Discord Activity iframe.
21+
</Card>
1922
<Card title="Channel troubleshooting" icon="wrench" href="/channels/troubleshooting">
2023
Cross-channel diagnostics and repair flow.
2124
</Card>
@@ -543,6 +546,18 @@ Use `bindings[].match.roles` to route Discord guild members to different agents
543546
</Accordion>
544547
</AccordionGroup>
545548

549+
## Discord Activities
550+
551+
OpenClaw uses a single Canvas entrypoint for Discord Activities:
552+
553+
- `/__openclaw__/canvas/`
554+
555+
Use a public HTTPS host (not internal-only LAN URLs), and enable Activity-scoped auth (`canvasHost.activity.*`) so Activity iframe traffic is authorized without exposing normal Gateway auth.
556+
557+
Agents can still render A2UI experiences inside Canvas when needed.
558+
559+
See the full guide: [Discord Activities](/channels/discord-activities).
560+
546561
## Native commands and command auth
547562

548563
- `commands.native` defaults to `"auto"` and is enabled for Discord.
@@ -1254,6 +1269,7 @@ High-signal Discord fields:
12541269
## Related
12551270

12561271
- [Pairing](/channels/pairing)
1272+
- [Discord Activities](/channels/discord-activities)
12571273
- [Groups](/channels/groups)
12581274
- [Channel routing](/channels/channel-routing)
12591275
- [Security](/gateway/security)

‎docs/channels/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Text is supported everywhere; media and reactions vary by channel.
1414
## Supported channels
1515

1616
- [BlueBubbles](/channels/bluebubbles) — **Recommended for iMessage**; uses the BlueBubbles macOS server REST API with full feature support (bundled plugin; edit, unsend, effects, reactions, group management — edit currently broken on macOS 26 Tahoe).
17-
- [Discord](/channels/discord) — Discord Bot API + Gateway; supports servers, channels, and DMs.
17+
- [Discord](/channels/discord) — Discord Bot API + Gateway; supports servers, channels, DMs, and an Activity-hosted Canvas surface.
1818
- [Feishu](/channels/feishu) — Feishu/Lark bot via WebSocket (bundled plugin).
1919
- [Google Chat](/channels/googlechat) — Google Chat API app via HTTP webhook.
2020
- [iMessage (legacy)](/channels/imessage) — Legacy macOS integration via imsg CLI (deprecated, use BlueBubbles for new setups).

‎docs/docs.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@
10061006
"pages": [
10071007
"channels/bluebubbles",
10081008
"channels/discord",
1009+
"channels/discord-activities",
10091010
"channels/feishu",
10101011
"channels/googlechat",
10111012
"channels/imessage",

‎extensions/discord/src/actions/handle-action.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ describe("handleDiscordMessageAction", () => {
7171
);
7272
});
7373

74+
it("passes activityLaunchButton helpers through send actions", async () => {
75+
await handleDiscordMessageAction({
76+
action: "send",
77+
params: {
78+
to: "channel:123",
79+
activityLaunchButton: true,
80+
activityLaunchLabel: "Open Canvas",
81+
},
82+
cfg: {
83+
channels: { discord: { token: "tok" } },
84+
} as OpenClawConfig,
85+
});
86+
87+
expect(handleDiscordActionMock).toHaveBeenCalledWith(
88+
expect.objectContaining({
89+
action: "sendMessage",
90+
to: "channel:123",
91+
activityLaunchButton: true,
92+
activityLaunchLabel: "Open Canvas",
93+
}),
94+
expect.any(Object),
95+
expect.any(Object),
96+
);
97+
});
98+
7499
it("rejects reactions when no message id source is available", async () => {
75100
await expect(
76101
handleDiscordMessageAction({

‎extensions/discord/src/actions/handle-action.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export async function handleDiscordMessageAction(
4747
if (action === "send") {
4848
const to = readStringParam(params, "to", { required: true });
4949
const asVoice = readBooleanParam(params, "asVoice") === true;
50+
const activityLaunchButton = readBooleanParam(params, "activityLaunchButton") === true;
51+
const activityLaunchLabel = readStringParam(params, "activityLaunchLabel");
5052
const rawComponents =
5153
params.components ??
5254
buildDiscordInteractiveComponents(normalizeInteractiveReply(params.interactive));
@@ -55,7 +57,7 @@ export async function handleDiscordMessageAction(
5557
(typeof rawComponents === "function" || typeof rawComponents === "object");
5658
const components = hasComponents ? rawComponents : undefined;
5759
const content = readStringParam(params, "message", {
58-
required: !asVoice && !hasComponents,
60+
required: !asVoice && !hasComponents && !activityLaunchButton,
5961
allowEmpty: true,
6062
});
6163
// Support media, path, and filePath for media URL
@@ -80,6 +82,8 @@ export async function handleDiscordMessageAction(
8082
filename: filename ?? undefined,
8183
replyTo: replyTo ?? undefined,
8284
components,
85+
...(activityLaunchButton ? { activityLaunchButton: true } : {}),
86+
...(activityLaunchLabel ? { activityLaunchLabel } : {}),
8387
embeds,
8488
asVoice,
8589
silent,

‎extensions/discord/src/actions/runtime.messaging.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,27 @@ export async function handleDiscordMessagingAction(
299299
const to = readStringParam(params, "to", { required: true });
300300
const asVoice = params.asVoice === true;
301301
const silent = params.silent === true;
302-
const rawComponents = params.components;
302+
const activityLaunchButton = readBooleanParam(params, "activityLaunchButton") === true;
303+
const activityLaunchLabel = readStringParam(params, "activityLaunchLabel")?.trim();
304+
if (activityLaunchButton && params.components !== undefined) {
305+
throw new Error("activityLaunchButton cannot be combined with components.");
306+
}
307+
const rawComponents = activityLaunchButton
308+
? {
309+
blocks: [
310+
{
311+
type: "actions",
312+
buttons: [
313+
{
314+
label: activityLaunchLabel || "Open Activity",
315+
style: "primary",
316+
action: "launch-activity",
317+
},
318+
],
319+
},
320+
],
321+
}
322+
: params.components;
303323
const componentSpec = hasDiscordComponentObjectKeys(rawComponents)
304324
? discordMessagingActionRuntime.readDiscordComponentSpec(rawComponents)
305325
: null;

0 commit comments

Comments
 (0)