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:

json
"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:

shell
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
StepThe kit checks or does
CategoryThe Proposals category exists (created if missing)
Review accountIt 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 componentInstalled (or updated), service_url and proposal_categories set, attached to the default and selectable themes
ServiceIts 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

  1. Category. Create a Proposals category. Note its id.

  2. Review account. Make a moderator account (xe_review) and an API key for it. This is the service's FORUM_KEY.

  3. 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:

    SettingValue
    service_urlThe review service, for example https://forum-review.example.org
    proposal_categoriesThe Proposals category
  4. Webhook. Add one in Admin, API, Webhooks:

    • Payload URL <service>/webhooks/discourse, content type application/json;
    • a random secret: the service's WEBHOOK_SECRET;
    • events: topic created, topic edited, post edited;
    • triggered categories: Proposals.
  5. Service. Configure and deploy it with the settings below.

#The service's settings

Secrets:

SecretWhat it is
WATCHER_KEYThe key of an address the reviewer lets ask for reviews
FORUM_KEYThe review account's Discourse API key
WEBHOOK_SECRETThe webhook's secret

Settings (all public):

SettingDefaultMeaning
FORUM_URLThe forum's address
FORUM_USERxe_reviewThe account the cards are posted as
CATEGORY, CATEGORY_IDproposalsThe Proposals category's slug and id
MODEaskask: review only approved topics. auto: review every topic in Proposals
APPROVAL_TAGxe-reviewThe tag a moderator adds to approve a review
APPROVEDTopic ids or text hashes approved ahead of time, comma-separated
DAILY_CAP3Forum reviews a day, counted on chain, within the reviewer's own daily cap
SPACE, REVIEWERThe Snapshot space and its XESnapshotReviewer
DELEGATESMembers' AI delegates, as Label=0x… pairs, for the card's stances
ARAGON_VOTING, ARAGON_URLAn Aragon TokenVoting plugin and its app's proposal URL, to follow Aragon votes
SNAPSHOT_URLWhere the card's Open the vote links Snapshot proposals
ALLOW_ORIGINSFORUM_URLOrigins 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

  1. A member posts in Proposals. The webhook (topic created or edited, or its first post edited) tells the service.
  2. 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.
  3. If the topic is approved (or MODE is auto) and the day's cap allows, it asks the reviewer for a review keyed by that hash, then publishes the answer when it lands.
  4. 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.

json
{  "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 }}
FieldValues
proposalfalse for a topic outside the Proposals category (and nothing else is returned)
stateclear, flagged, unreadable, reviewing, failed or none
verdict, risk, intentThe published review's fields; null until it's published
cutThe length of text reviewed when the draft was too long to review whole; 0 otherwise
delegates[].stancefor, against, abstain, deciding or none
trackerThe 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:

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