Discourse setup
Add XE's AI review to a Discourse forum's proposals, with the kit or by hand. The review service's settings, its webhook and its topic API.
XE's forum review service reviews each topic in a Discourse forum's Proposals category with XE's attested AI, and posts the result as a card in the topic. A theme component shows the live card, with the vote and the AI delegates' stances. What members and moderators see: AI review for Discourse.
It reuses the DAO's Snapshot reviewer contract (XESnapshotReviewer): a forum draft is reviewed under the hash of its text, rendered exactly as the Snapshot proposal it will become. So the same text posted on Snapshot already has its review. Set up Snapshot first: XE AI for your DAO.
The reviews run on your DAO's own provider account, through the XE Key Service. See Your DAO's own provider account.
#What you need
- A Discourse forum and an admin API key. Hosted forums work: setup uses only the admin API.
- A moderator account for the service to post its cards as, for example
xe_review. - The DAO's XESnapshotReviewer, and an address allowed to ask it for reviews (the watcher).
#With the kit
Add a discourse block to the kit's config:
"discourse": { "url": "https://forum.example.org", "admin": { "username": "admin", "keyFile": "~/.config/example-dao/discourse-admin.key" }, "reviewAccount": "xe_review", "category": "proposals", "serviceUrl": "https://forum-review.example.org", "serviceKeyFile": "~/.config/example-dao/forum-review.key", // written by the kit "webhookSecretFile": "~/.config/example-dao/forum-webhook.secret", // written by the kit "approvalTag": "xe-review", "dailyCap": 3}Then run it:
node dao/kit/xe-dao-kit.mjs discourse --config dao.json --dry-run # what it would donode dao/kit/xe-dao-kit.mjs discourse --config dao.json # do itnode dao/kit/xe-dao-kit.mjs discourse --config dao.json --verify # check; exits 1 on a failure| Step | The kit checks or does |
|---|---|
| Category | The Proposals category exists (created if missing) |
| Review account | It exists, and its API key is in serviceKeyFile (created if missing) |
| Webhook | <serviceUrl>/webhooks/discourse, JSON, on topic created, topic edited and post edited, for the Proposals category, signed with the secret |
| Theme component | Installed (or updated), service_url and proposal_categories set, attached to the default and selectable themes |
| Service | Its configuration in out/<name>/; it answers a CORS preflight from the forum's origin |
Set the service's three secrets (below) and deploy it with the commands the kit prints. Keys are read from the files the config names and never printed.
#By hand
-
Category. Create a Proposals category. Note its id.
-
Review account. Make a moderator account (
xe_review) and an API key for it. This is the service'sFORUM_KEY. -
Theme component. Install the XE AI review component from XE's kit (
dao/discourse/theme) under Admin, Customize, Themes. Set its two settings and add it to your themes:Setting Value service_urlThe review service, for example https://forum-review.example.orgproposal_categoriesThe Proposals category -
Webhook. Add one in Admin, API, Webhooks:
- Payload URL
<service>/webhooks/discourse, content typeapplication/json; - a random secret: the service's
WEBHOOK_SECRET; - events: topic created, topic edited, post edited;
- triggered categories: Proposals.
- Payload URL
-
Service. Configure and deploy it with the settings below.
#The service's settings
Secrets:
| Secret | What it is |
|---|---|
WATCHER_KEY | The key of an address the reviewer lets ask for reviews |
FORUM_KEY | The review account's Discourse API key |
WEBHOOK_SECRET | The webhook's secret |
Settings (all public):
| Setting | Default | Meaning |
|---|---|---|
FORUM_URL | The forum's address | |
FORUM_USER | xe_review | The account the cards are posted as |
CATEGORY, CATEGORY_ID | proposals | The Proposals category's slug and id |
MODE | ask | ask: review only approved topics. auto: review every topic in Proposals |
APPROVAL_TAG | xe-review | The tag a moderator adds to approve a review |
APPROVED | Topic ids or text hashes approved ahead of time, comma-separated | |
DAILY_CAP | 3 | Forum reviews a day, counted on chain, within the reviewer's own daily cap |
SPACE, REVIEWER | The Snapshot space and its XESnapshotReviewer | |
DELEGATES | Members' AI delegates, as Label=0x… pairs, for the card's stances | |
ARAGON_VOTING, ARAGON_URL | An Aragon TokenVoting plugin and its app's proposal URL, to follow Aragon votes | |
SNAPSHOT_URL | Where the card's Open the vote links Snapshot proposals | |
ALLOW_ORIGINS | FORUM_URL | Origins allowed to read the topic API |
The service also runs every two minutes, so a missed webhook only delays a review.
#How a review runs
- A member posts in Proposals. The webhook (topic created or edited, or its first post edited) tells the service.
- The service renders the draft as the Snapshot proposal it becomes (the space, the title, For / Against / Abstain and the first post's raw text) and hashes it with SHA-256.
- If the topic is approved (or
MODEisauto) and the day's cap allows, it asks the reviewer for a review keyed by that hash, then publishes the answer when it lands. - It posts or updates one card in the topic. An edit is a new text with a new hash, and gets a new review.
Webhook calls must carry Discourse's X-Discourse-Event-Signature for the secret; anything else is refused with 401.
#Reading a topic's review
GET <service>/v1/topics/<topic id> returns what the card shows. It answers the origins in ALLOW_ORIGINS and is cached for 30 seconds.
{ "topic": 42, "proposal": true, "state": "flagged", "textHash": "0x5f097ad7…", "verdict": "flag", "risk": "high", "intent": "differs", "doesMore": "yes", "summary": "Points the market's price source at an address the DAO has not named…", "risks": ["The intent says no funds move, but the second action grants an unlimited USDC allowance."], "proof": { "url": "https://sepolia.basescan.org/tx/0x…", "reviewer": "0x2375A274064F4f40f9339C4267f496F0b7dD1fF0", "chainId": 84532, "outputHash": "0x…", "attestationHash": "0x…" }, "delegates": [{ "label": "Member 2", "address": "0x02Ec…4190", "stance": "against", "line": "Voted Against." }], "tracker": { "snapshot": { "id": "0x…", "url": "https://snapshot.example.org/#/proposal/0x…", "state": "active", "sameText": true }, "aragon": null }}| Field | Values |
|---|---|
proposal | false for a topic outside the Proposals category (and nothing else is returned) |
state | clear, flagged, unreadable, reviewing, failed or none |
verdict, risk, intent | The published review's fields; null until it's published |
cut | The length of text reviewed when the draft was too long to review whole; 0 otherwise |
delegates[].stance | for, against, abstain, deciding or none |
tracker | The Snapshot and Aragon votes the topic leads to, with their tallies, or null |
Reading it from a script, for example to list the forum's flagged drafts:
const service = "https://forum-review.example.org";for (const id of [41, 42, 43]) { const r = await fetch(`${service}/v1/topics/${id}`).then((x) => x.json()); if (r.proposal && r.state !== "clear") console.log(id, r.state, r.summary ?? "");}Run it from a server, or from a page on an origin in ALLOW_ORIGINS.
#Checking a review yourself
The card's proof is on chain. reviewOfText(textHash) on the reviewer finds the published review of a text by its hash, and isClear(key) says whether it passed. The reviewer's other reads, and how to check its attestations, are in XE AI for your DAO.