Conformance checklist
A bot is a member of encrypted chats, so it has duties every member's phone counts on. @peachysocial/bot does all of them for you. This page lists them, for two readers:
- anyone building on the SDK who wants to know what it's doing;
- anyone building a bot without the SDK, which Peachy checks against this list before verifying it.
What every bot must do#
- Make its own keys. Mint the bot's account key, certify its one device with it, and register the bot's own access key.
- Keep its keys fresh. Refresh its credential before it expires (30 days), and rotate its key in every group it's in on schedule (every 7 days or 250 messages), with updates that change nothing but its own keys.
- Stay reachable. Publish key packages and refill them, keeping a last-resort package.
- Say only what it should. Send a hello after each join. Send typing only while it answers a message, to people's devices and never to other bots, and stop it once it replied or gave up. Run a bare
/nameonly when no bot added to the chat after it listsname(it runs on the newest bot that has the command), and post on its own only withpost: a reply to a mention always goes, in its thread. In a group where only admins send messages (Send messages: Only admins), post nothing to the main chat (a bot is never an admin): reply in threads, without "also send to the chat". Drop a post to the main chat from a member who may not post there, as members' devices do. Never send read marks, and never send anyone's key but its own. - Help members catch up. Answer resend requests for 14 days from its own send log. Ask for messages it missed only once, and treat a refused or throttled gap as final.
- Handle shared history correctly. File a history share only when it names your bot, keep only the sharer's own messages from before your bot joined (never another member's: drop any entry by someone else), and treat every name on them as the sharer's claim.
- Never manage the group. Leave only through the protocol's leave step. Never commit other members' proposals. Add only people, and only where any member may add; never remove anyone or change the group's settings. Everyone a bot invites gets the group as a request from the bot, as from anyone they don't know. In a community's groups only admins add people or bots, so a bot invites nobody there: every community's group is run by its admins (below). In a community's room that needs updating first (any group whose own
cmnames the community, not yet run by its admins, as every person's app reads it), invite only people in the community: Peachy tells a bot no roster, so a bot invites only someone in the community's own group (cg), when the bot is seated there and the core seats that group's people into the room (ownerTreeSeats). The community's own group is the one the core pins for it (pins), fed the server'sgroup_handle(MatchCommunityGroupHandles), as on every person's device; a pin moves only to its group's honored re-founding. A bot that isn't in the community's own group invites nobody into its rooms. No group's claim is evidence: not another room's people, nor a group anyone founded calling itself the community's, whatever its directory lists. A group brought in (lst.calone) follows its own rules.@peachysocial/botasks the core and does this for you:chat.inviterefuses anyone else (notInCommunity). In a group run by its admins (governed: only admin devices commit, and Peachy refuses an unstamped commit), commit nothing: ask the core per group (commitsHere), and where it says no, renew your own leaf as a person's device does, with an own-scope commit (submitted withscope = OWNwhen the core'scommitStampanswersown), and add nobody: only admins add there. Never retry a commit refused asunstamped. A leaf that lapses anyway sends nothing: ask back in and tell the operator. Ask back in as a person's device does, when the core's schedule says (resyncWant, thenresyncAsksDue, noting each sent ask withresyncAsked); hand every resync answer toresyncOffer, join withresyncJoinat a head you read then, submitted own-scope, and on a refused submit callresyncRefused. Answer no seat ask and confirm nobody. Follow only a re-founding whose founder was an admin in the state you kept, also while asking back in after losing the group; leave the new group when you were leaving the old one. - Enforce its reach policy. Leave a group someone outside it added it to, ignore its own chat with someone outside it, and never answer a request to seat someone.
- Follow disappearing messages. Honor a chat's disappearing-messages timer by default, in everything it keeps (events it failed to handle included), drop what it kept of a message deleted for everyone or of a chat it left, and keep separate state for each group, up to 1,000 groups.
- Identify itself. Send every message from its own device, and every call with its own session.
- Call only when asked, and leave when told. Start a call only in a group, in answer to a person's message from the last 10 minutes that asks the bot (in a group set to Only admins, an admin's), never ringing, and one call per ask, also when a handler runs again. Join the call already going on in a group instead of starting another, as a person's call button does, and say
Joinedevery 10 seconds while in it, as people's devices do. Answer another participant's signedJoinedwith your own (not within 10 seconds of your last unless they're new to you in that call, and never twice in 30 seconds to one participant), and after a beat that failed, make the next one signed. No calls in the bot's own DM yet; they're coming. Take audio and video only from people who said OK to it. Leave at once when anyone in the call removes it; never join that call again, and start none in that chat for 10 minutes. Honor aRemoveof anyone else in the call by the rule people's devices use (a bot's from anyone in the call, a person's only from an admin): never answer or bind that participant again in that call, and rotate your media key past them (the core's call-mediaremovewith their participant id). - Keep the call's media keys as people's devices do. In a call, run the core's participant media keys by the rekeying requirements (R-K10) in
docs/protocol/calls.md. The core does none of these for you:- Join with
startunder the participant id the media server answered, then your signedJoined, thenshare, and send every envelope a door returns, in order. Astartthat fails fails the join (R-K10.1). - When an open grants your bot an advance (
rotated = false) from a leaf that already granted it a key since your laststart, and that you haven't since seen leave (you removed it, or opened its signedLeft),shareagain: that participant dropped your bot and bound it anew with no key of yours (R-K10.9). Forget a leaf you saw leave: when it joins again, your own advance reaches it, and its first grant to your bot is a first one, not answered. So is the first grant after a signedJoinedfrom a leaf naming a call key other than the one in its last signedJoinedsince yourstart(a fresh core there: a reload, a killed app); the firstJoinedyou hear from a leaf marks nothing. Answer any number of advances with one share that begins after them, at most one such share per 10 seconds in a call: an advance sooner than that waits for the next share, and is never dropped. Sharing after every signedJoinedyou send, as@peachysocial/botdoes, also meets this. - Take out a person you hold bound who sent no
Joined, signed or live, for 30 seconds, with the core'sremovefor their leaf, which rotates your key past them (R-K10.2). Only a bot that could hear judges: while your own event stream or media session is down, take out only those silent for 90 seconds, and when it comes back, everyone's 30 seconds start again. A check more than 15 seconds after the one before takes out nobody and counts everyone as heard. Never take out another bot: its liveJoineds go only to people's devices, so it goes by its signedLeft, aRemove, or a commit that takes its leaf. - A live
Joinedfrom someone you don't hold bound (one you took out, or whose signedJoinedyou missed) gets your signedJoined, by the answer limits in item 11 (R-K10.2). - Call
epochon every epoch change (R-K10.3). Callapplyonce an answer'sapplyAfterMshas passed, arming again from each answer (R-K10.4). Reloadkeysafter every open that granted or announced a key, every epoch change, rotation andapply, and every answer that reportsapplied, and send media only under exactly what it returns (R-K10.5). - On
CALL_STATE_LOSTfromkeysor from sealing yourJoinedwhile in the call,startagain under the same participant id, session and tracks, and end the call if thatstartfails (R-K10.8).
- Join with
Check your bot#
@peachysocial/bot-conformance runs the checks it can for you, against your bot in the same in-memory Peachy npx @peachysocial/bot dev uses. It is published with the SDK at launch. From your project:
npm i -D @peachysocial/bot-conformance
npx @peachysocial/bot-conformanceIt loads your bot the way npx @peachysocial/bot dev does: bot.ts or src/bot.ts (or the file you name), calling its dev(bot) if it exports one, else register(bot). Then it sends your bot what real people send: plain messages, mentions, /help, every command bare and with very long or odd text, in its own chat, in a group that gives it no permissions (where a mention must still be answered), and in a group where only admins send messages (where it must post nothing to the main chat). It writes to it from outside its reach, and reads your project for how the store key is kept.
Each line of the report is one of:
- ok: checked here, and it held.
- FAIL: checked here, and it didn't. The line says why. A failure blocks verification until it's fixed.
- sdk: a protocol duty from the list above that
@peachysocial/botcarries out for you. - todo: a duty this tool can't see, because the bot isn't built on
@peachysocial/bot. Someone at Peachy works through it with you. - skip: not run, because there was nothing to run it on (no bot file, or no project directory). The line says which.
It exits 1 when a check failed, so it can run in your CI. --json prints the report as JSON.
The release checklist#
The SDK is built to meet each line, and a bot not built on it shows each one before it's verified.
- [ ] Its own access key. The bot registers its own access key and puts it in its hellos. It never sends anyone else's access key or profile key.
- [ ] Encrypted store, key kept apart. Everything the bot stores is encrypted. The key lives outside the store, in the host's secret store or an environment secret, never in the store or beside it.
- [ ] Commits through the right door only. The bot applies a group change only through the protocol core's entry point for that kind of delivery, so the core applies that kind's rules. It never applies one raw.
- [ ] Removes nobody. The bot never removes a member, stale or retired devices included: people's devices do that (
removeStaleLeaf). - [ ] Takes no unvouched account key. The bot takes an account key only from its own mint, or from its own store copied whole with
npx @peachysocial/bot store copy. A new server without the store is a key reset (Link a new server). - [ ] Pinned server keys. The bot ships with Peachy's server keys pinned, and refuses a server that doesn't present them.
- [ ] Its own version, not an app's. The bot sends its SDK version in
x-peachy-sdk, and never sendsx-peachy-build, the header Peachy's apps use. Peachy refuses bot sessions below its published minimum SDK version.
Staying current#
Peachy decides when its apps update, but your bot updates when you get to it. So when a message format changes:
- Peachy publishes the oldest formats it accepts, and the date the next one stops working, in an answer that is the same for everyone. The SDK reads it at start and every hour, and from 90 days before the date logs a warning (daily, then hourly in the last 7 days) and reports a
floorWarningstatus. A bot below the minimum version is refused at start withsdk_update_required. - A send refused for a retired format says
envelope-retiredon the wire (format_retiredin the SDK), so you know to update the SDK. - Peachy never retires a format that the latest published SDK can't replace.
- Every format change is in the public protocol changelog, with the first SDK version that writes the new format and the date the old one goes away.
Bots not built on the SDK#
Before verifying a bot that doesn't use @peachysocial/bot, someone at Peachy works through this list with you from test accounts: sending it malformed messages, writing to it from outside its reach policy and expecting no answer, and checking its hellos, its resend answers, its typing and that it sends no read marks. For a bot that calls, they also check that a test account which goes silent for 40 seconds is taken out and rotated past, and that one which drops the bot (the bot's heartbeats to it blocked for 40 seconds while its own stream stays up, then let through) hears and sees it again. What that turns up is the evidence for verification.
If you're writing your own, start from the protocol documents and replay the protocol's published test vectors: the SDK's suite does the same.