|
| 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) |
0 commit comments