ADR-0044: Live chat after a handoff, and the vendor adapters
- Status: Accepted on 2026-12-04 by the maintainer, with every recommendation (see "Settled with the maintainer"). Built by tasks 0.9-h1 to h5, after 0.9-b1 makes room.
- Date: 2026-12-04
- Amends: ADR-0030 (decision 8: the bot stops while a person writes; new handoff states; a live channel next to
onHandoff), ADR-0033 (decision 4: a person's reply reaches the page asmessage.received) and ADR-0013 (message.receivedgainsfrom). - Related: ADR-0004, ADR-0006, ADR-0022 (developer notes), ADR-0024, ADR-0027, ADR-0028, ADR-0031, ADR-0032, ADR-0041 (it takes React room first).
- Evidence: a prototype on a local branch,
spike/live-chat-0044, never pushed or merged. Vendor APIs were checked in their official docs on 2026-12-04 (links in decisions 8 and 9). OpenAI's Conversations API was checked in its OpenAPI spec through theopenaiDeveloperDocsserver on the same day.
Context
askdare 0.7 hands a conversation to a person one way (ADR-0030): a report goes to a webhook or a mailbox, the person answers by email, and the bot keeps answering. ADR-0030 left two promises for 0.9:
- decision 8: "a setting to stop the bot after a handoff waits for live chat … where it means 'a person is now writing here'";
- ADR-0033 decision 4: "a human's reply in the chat must reach the page as
message.received, or the badge misses it."
The maintainer chose the adapters on 2026-12-02 (ROADMAP, #300): Slack with live chat, HubSpot and Zendesk one-way, each creating a ticket. Two-way HubSpot (Custom Channels) and Zendesk (Sunshine Conversations) need paid tiers and stay under Later.
What bounds the design:
- No open connection between turns. The chat talks to the server only while a turn streams (ADR-0027). A person's reply arrives whenever the person writes.
- No database and no pub/sub of askdare's own (ADR-0003). Conversations live in the app's
ConversationStore(OpenAI Conversations, Postgres, or memory in tests), and counters in the rate-limit store (memory or Upstash). - Serverless hosts. Vercel and similar hosts run a function per request, up to the route's
maxDuration. Nothing runs between requests: no timers, no background workers. - The client chooses nothing (ADR-0004), and every rendered text is sanitized.
- The budgets. After 0.8, by CI's zlib: 344 B left in the React entry and 292 B in the headless case. ADR-0041 (runtime themes, accepted) takes about 140 B and 45 B of that, leaving about 204 B and 247 B. The loader has 348 B left, and ADR-0041 takes about 141 B of it.
What the prototype measured
Bytes
The prototype adds the chat side of live chat to main:
- the new handoff states;
authorandnameon history messages;POST /liveread every 3 seconds while a handoff iswaitingorliveand the page is visible, slowing to 15 seconds after a minute without a reply, and sending the visitor's text through the same request;- the person's replies added to the message list;
message.receivedwithfrom: 'person'for each reply;- a
MessageAuthorprimitive (the person's label) in the default look.
The state line needed no new code: HandoffStatus already shows handoff.<state>. Texts come from the server's configuration, so they add nothing to the bundles (checked: the default dictionary isn't in dist/react.js). Sizes are gzipped, measured with scripts/react-size.mjs and scripts/inline-assets.mjs on a laptop. CI's zlib compresses about 30 B worse per bundle, so the "left" column uses ADR-0041's CI figures.
| What | main | Prototype | Added | Left after ADR-0041 (CI) | Left after both (CI estimate) |
|---|---|---|---|---|---|
React entry (react.js) | 34,343 | 34,680 | +337 | 204 | −133 |
Headless (Root and useChat) | 11,966 | 12,243 | +277 | 247 | −30 |
Embed (EmbedRoot and useChat) | 12,734 | 13,015 | +281 | 1,412 | 1,131 |
| Iframe app | 44,400 | 44,749 | +349 | 6,177 | 5,828 |
| Loader | 5,284 | 5,289 | +5 | 175 | 170 |
- The loader's 5 B is
from: 1inembed/host-events.ts, the loader's allowlist of event fields. That allowlist is typed fromChatEvent, so a new field onmessage.receiveddoesn't compile without it. Without the field, the page wouldn't seefrom, but the badge would still count the reply (it countsoutcome: 'completed').embed/loader.tsitself doesn't change. - The prototype is the minimum. h2 adds the composer's placeholder while
waiting, the state line's placement and screen reader details. This ADR budgets +420 B in the entry and +350 B in the headless case for h2, about 25% over the prototype.
A lazy chunk is bigger, not smaller
Moving the reading loop into a chunk loaded with import() when a handoff becomes waiting was measured too. Rolldown then splits the whole entry into an entry chunk and a shared chunk, and the first load grows:
| What | Eager (prototype) | Lazy: first load | Lazy: live chat chunk |
|---|---|---|---|
| React entry | 34,680 | 35,671 (9,508 + 26,163) | 361 |
| Headless | 12,243 | 12,295 (71 + 12,224) | 356 |
| Embed | 13,015 | 13,404 (1,433 + 11,971) | 360 |
react-size.mjs counts every chunk, so the lazy variant also fails the check as it is measured today. A lazy chunk is rejected (decision 7).
Polling against the stores
A test on the spike branch (src/spike-live/poll.test.ts) models POST /live: one page({ limit: 20 }) read, then the items after the client's cursor (the ID of the newest item it has seen).
- Memory store: 0.053 ms per read on a 200-item conversation. One store call per read, and only new items come back; a quiet read returns nothing.
- Postgres (
@boldare/askdare-postgres):page()is oneorder by seq desc limit Nquery on the conversation's index, so a read costs one indexed query. - OpenAI Conversations: a read is one
GET /conversations/{id}/items(order,limit1 to 100,afteran item ID; OpenAPI spec, 2026-12-04). It uses no tokens and counts against the project's request rate limit; the spec documents a429and no separate limit. Items carry no timestamps, so times go in the notes (decision 3).
At 3 seconds, a visitor in a live chat costs about 20 reads a minute, and about 4 a minute after the backoff. Each read is a function invocation on serverless hosts.
Decision
1. The states and who moves them
A live handoff adds four states after requested, beside ADR-0030's six:
waiting: the request reached the live channel and nobody has joined yet.live: a person has written in the conversation.ended: the person ended it, or nobody wrote foridleMinutes.missed: nobody joined withinwaitMinutes. The request stays in the channel, as a one-way handoff would.
| From | To | Moved by |
|---|---|---|
requested | waiting | the live channel's open() succeeded (instead of sent). A failure goes to saved or failed as in ADR-0030. |
waiting | live | the channel's first inbound message from a person |
waiting | missed | waitMinutes (default 10) with no person's message |
live | ended | the person ends it in the channel (Slack: decision 8), or idleMinutes (default 30) with no message from either side |
Timeouts need no scheduler. The server checks the times whenever it reads the state: on POST /live, on POST /messages, on POST /history and on an inbound event. If a timeout has passed, it appends the state's note and tells the channel (close()). When the visitor has left and the person never writes again, the channel is told on the next inbound event. The adapter then answers in the thread that the chat has ended.
The visitor ends a live chat by starting a new conversation, which is the existing action. The old conversation ends at its idle timeout. A visitor's "End chat" button is Later: it costs bytes in the headless case, and a visitor who leaves doesn't press it.
What the visitor sees, as new texts in all seven languages (h2 fixes the wording):
handoff.waiting: "Waiting for a person to join. You can write to them here."handoff.live: "You're chatting with a person from our team."handoff.ended: "The chat with our team has ended. I'm back to help."handoff.missed: "Nobody could join right now. The team has your request and will get back to you if you left a way to reach you."handoff.person: the label on a person's messages ("Team").
2. Turning it on
defineBot({
handoff: {
form: 'handoff',
content: 'summary', // what the person sees when the thread opens (ADR-0030)
live: {
waitMinutes: 10, // 1–120: nobody joined → missed
idleMinutes: 30, // 1–240: nobody wrote → ended
names: false, // show the person's display name instead of `handoff.person`
limits: { perMinute: 10, perConversation: 200 }, // the visitor's live messages
},
},
});
createChatHandler({ bots, liveChannel: slackHandoff({ token, signingSecret, channel }) });live: trueis a shortcut for the defaults. A bot withliveand a handler withoutliveChannelfails at startup, anddoctorsays so, as foronHandoff(ADR-0030 decision 1).- One live channel per handler. The adapter routes bots to channels itself (Slack:
channelas a string or a function of the bot). A bot withoutliveusesonHandoffif it is set, and otherwise the live channel's one-way post. SoliveChannelalone also covers one-way bots. - The bot is silent from
waitinguntilendedormissed. NostopBotoption: a bot that answers while a person writes, or while the visitor waits for one, makes two voices in one chat. While the bot is silent:- the visitor's message runs no model call and goes to the channel, stored in the conversation;
- it is charged no tokens and no bot budget;
- it has its own limits:
perMinuteper visitor, and per IP grouped by /64 as ADR-0030's are;perConversationfor the whole live chat; and the bot'smaxInputChars; - over a limit, the chat shows the existing
rate_limitederror.
- Handoff limits (ADR-0030 decision 7) count a live handoff when it is accepted, as before. The docs suggest
perConversation: 2for live bots, so a visitor whose handoff wasmissedcan ask again later.
3. Where a person's messages live
In the conversation store, so history, reloads, the console and the next model call see them. Every store works unchanged; no port change.
- A person's message is an
assistantmessage preceded by a developer note:[askdare:live] person <epoch ms>, with the display name after it whennamesis on (at most 64 characters, plain text). Both go in oneappend, so they stay together.- The
assistantrole keeps the person's words out of developer authority (unlike a note) and out of the visitor's voice (unlike ausermessage). - The note tells the model that a person wrote them, not the model itself.
- The
- The visitor's message while the bot is silent is a
usermessage preceded by[askdare:live] visitor <epoch ms>. - State changes are notes too:
[askdare:live] waiting|live|ended|missed <epoch ms> [target], with fixed sentences as in ADR-0030. For example,ended: "The person from the team finished the chat; you answer again. Do not repeat what they said."waitingcarries the channel'starget(decision 5). The latest note gives the state, and its time drives the timeouts, since OpenAI's items carry no time (atis 0). - On OpenAI Conversations the items go through
POST /conversations/{id}/items, which takes up to 20 input items per call,assistantmessages included (spike S7 did the same). It refuses an append while the conversation is locked by a running response. That happens when the model'shandoffcall is still streaming its last words as the person replies. The inbound side therefore retries the append with backoff for up to 20 seconds (decision 5). On item stores, aVersionConflictErrorgets the same retry (0.8.x-p4 fixes the related turn-side conflict). - History returns a person's message as
role: 'assistant'withauthor: 'person'and, whennamesis on,name. It has no feedback handle, citations or reply options: a visitor doesn't rate a person's message. The notes themselves aren't shown. - What the model reads after
ended: the live transcript, between the notes, at normal input cost. Long live chats grow the context. Item stores compact as ADR-0029 says, anddocs/costs.mdmentions it.
4. Getting replies to the widget: polling POST /live
Recommended: polling. While the latest handoff is waiting or live, the chat posts POST /live every 3 seconds, and every 15 seconds after 20 quiet reads in a row (about a minute). It reads only while the page is visible (visibilitychange), resumes when the page shows again, and stops when the state ends or the chat stops. The visitor's own message goes through the same request (text), so live chat has one endpoint and one loop.
- Several instances: each read takes the newest page of the conversation store and returns the person's messages after the client's cursor. The store is the shared truth, so no pub/sub is needed.
- This holds for every store that is shared: OpenAI Conversations, Postgres, any
ConversationStoreadd-on. - It doesn't hold for the memory store across instances, which already can't serve several instances, and
doctorwarns about it in production (0.8.x-p1).
- This holds for every store that is shared: OpenAI Conversations, Postgres, any
- The cost per live visitor is at most about 20 reads a minute. That is one indexed query (Postgres), a map lookup (memory) or one
GETwith no tokens (OpenAI) each, plus a function invocation on serverless hosts. It lasts only while a person is asked or writing and the page is visible. - Latency: a reply shows within 3 seconds while the chat is active, and within 15 after a quiet minute. That is acceptable for a person typing in Slack.
A held SSE stream was considered and not chosen (see "Alternatives"). Without pub/sub, the server would still read the store in a loop, only inside a function held open up to maxDuration, which serverless hosts bill by duration. It would also need reconnects, and proxies that buffer streams break it. Polling can later shorten to long-polling (holding a read up to about 20 seconds) without a protocol change beyond an optional wait field.
5. The live channel port
One-way adapters stay plain onHandoff functions (ADR-0030 decision 5). HubSpot and Zendesk are those (decision 9). A live channel adds an inbound side:
interface LiveChannel {
/** The route segment: `POST <basePath>/handoff/<name>`. `[a-z0-9-]{1,32}`. */
readonly name: string;
/**
* Posts the request. With `ref`, it opens a live chat and must carry `ref` so that every inbound
* event about it can hand it back. Without `ref`, it is a one-way post. Resolves to the channel's
* own target for later `send` and `close` calls (Slack: channel and thread). Throws on failure.
*/
open(report: ChatHandoffReport, live?: { ref: string; signal: AbortSignal }): Promise<string>;
/** Posts the visitor's message to the target. */
send(target: string, message: { text: string; at: number }, signal: AbortSignal): Promise<void>;
/** Tells the person it ended: `person`, `idle`, `missed`, or `gone` (the conversation was deleted). */
close(target: string, reason: LiveEndReason, signal: AbortSignal): Promise<void>;
/**
* Verifies an inbound request (signature, timestamp) and parses it. Returns the response for the
* vendor (Slack's URL challenge, an acknowledgement) and the events to apply.
*/
receive(request: Request): Promise<{ response: Response; events: readonly LiveEvent[] }>;
}
type LiveEvent =
| { kind: 'message'; ref: string; id: string; text: string; name?: string }
| { kind: 'end'; ref: string; id: string };- How an inbound event finds its conversation: askdare gives
open()a sealed reference,ref. It is a JWE like the resume token (ADR-0004:dir+ A256GCM, keys fromCHAT_SECRETby HKDF, its owntyp,aud= the bot, 30 days, rotation throughCHAT_SECRET_PREVIOUS). It carries the conversation ID and the handoff'sid.- The channel stores it where its vendor hands it back, and askdare stores no mapping. Slack puts it in the request message's
metadata(decision 8). - An event whose
refdoesn't open, or whose conversation is gone, is acknowledged and dropped. The channel is toldgoneonce, so the person learns the visitor left. - The reference is encrypted, so the conversation ID never reaches the vendor in clear.
- The channel stores it where its vendor hands it back, and askdare stores no mapping. Slack puts it in the request message's
- The inbound route
POST <basePath>/handoff/<name>has none of the browser endpoints' checks (origin, access token): the vendor calls it, and onlyreceiveauthenticates it.- The body is capped at 64 KB, and requests are rate-limited per IP.
- It answers within the vendor's deadline (Slack: 3 seconds).
receiveand the acknowledgement run first; appending and the timeouts run after the response throughwaitUntilorafter(), with the append retry of decision 3. - Replay: the vendor's timestamp window (Slack: 5 minutes, checked in
receive), and each event'sidclaimed once for 10 minutes in the rate-limit store. That is the same one-time claim forms use (claimForm), shared across instances with Upstash.
- Public (ADR-0006):
LiveChannel,LiveEvent,LiveEndReasonand theliveChanneloption ofcreateChatHandler, from@boldare/askdare/next;handoff.liveand its types indefineBot;memoryLiveChannel()in@boldare/askdare/testingfor apps' own tests and h1's. Sealing and openingrefstay internal: a channel treatsrefas an opaque string.
6. The protocol (additive in version 1)
Each goes into docs/protocol.md, with fixtures (protocol-0.9.test.ts, on the model of protocol-0.7.test.ts):
HandoffStategainswaiting,live,endedandmissed: in thehandoffevent, inPOST /handoff's andPOST /forms's answers, and in history'shandoff.state. An old client shows an unknown state as nothing, as it ignores unknown values.- History messages gain
author?: 'person'andname?: string(1 to 64 characters, plain text). POST /live { botId, resumeToken, after?, text? }, with the access token, the resume token owning the conversation, and the same-origin checks every endpoint has. It answers200 { state, messages, after? }:messagesholds only the person's messages afterafter, as history messages. The visitor's own messages aren't echoed back.afteris the newest item's ID, opaque to the client.textis the visitor's message, sent to the channel and stored, answered without a turn.- In a state other than
waitingorlive, it answers the state and no messages, and refusestextwith409. 404for a bot withoutlive;429for its burst limit.
POST /messageswhilewaitingorliveanswers409with a new error code (h1 names it, for examplelive_chat), so an old client gets an error instead of a model answer.- The browser event
message.receivedgainsfrom: 'person'for a person's reply, withoutcome: 'completed',durationMs: 0andcitations: 0. The bot's answers carry nofrom. The loader's field allowlist gainsfrom(decision 7). - The inbound route
POST <basePath>/handoff/<name>is the channel's, not the chat's, and is documented with the adapter.
7. The chat and its budget
- A person's message renders in the message list with
data-author="person"and a label (MessageAuthor, partauthor: the name orhandoff.person). Its text goes through the same Markdown renderer and sanitizer as answers, with the same link allowlist. "Sanitized like model output" then costs no extra code, where a plain-text branch would. The adapter turns its vendor's formatting into plain Markdown (Slack: decision 8). - The state line is the existing
HandoffStatuswith the new texts. Whilewaiting, the composer's placeholder becomeshandoff.waiting, so the visitor knows they can write. - A person's reply is announced once to screen readers, as answers are, and never moves focus. It emits
message.receivedwithfrom: 'person'. The loader's badge counts it with no change toembed/loader.ts. The loader's field allowlist,embed/host-events.ts, gainsfrom(+5 B, measured). h2 makes that one-line change after r1c, which owns the loader in 0.9. - The budget: b1 makes room first; no lazy chunk; no budget raise.
- Added by h2 (estimate): +420 B in the entry and +350 B in the headless case. ADR-0041's React part adds +140 B and +45 B. ADR-0028 wants about 100 B of headroom for
markedpatches in the entry. - b1 frees at least 350 B in the React entry and 200 B in the headless case, measured on CI from 0.8's 344 B and 292 B left. That is 140 + 420 + 100 − 344 ≈ 316 B and 45 + 350 + 50 − 292 ≈ 153 B, rounded up.
- If b1 can't reach that with the same behavior, it stops and says so with the numbers. A budget raise then needs its own ADR under ADR-0028, as decision 3 there says.
- A lazy live chat chunk is rejected: measured, it makes the first load larger in every case.
- Added by h2 (estimate): +420 B in the entry and +350 B in the headless case. ADR-0041's React part adds +140 B and +45 B. ADR-0028 wants about 100 B of headroom for
8. Slack: a channel per bot, a thread per conversation
Checked in Slack's docs on 2026-12-04.
- Each team creates its own internal app from a manifest in the docs, so there's no Marketplace listing.
- Scopes:
chat:write,channels:history(orgroups:historyfor a private channel) andreactions:read. - Events:
message.channels(ormessage.groups) andreaction_added, at the Request URL<basePath>/handoff/slack. - Internal apps keep Tier 3 for
conversations.history(50+ requests a minute). The 2025 cut to 1 request a minute applies to commercially distributed apps that aren't in the Marketplace (changelog 2025-05-29). - Socket Mode needs a long-lived process, so it doesn't fit serverless hosts, and Request URLs do.
- Scopes:
- Opening:
chat.postMessageposts the report to the bot's channel, as plain text with the report's content level.metadatais{ event_type: 'askdare_handoff', event_payload: { ref } }.- Slack says metadata is readable by any member of the workspace.
refis encrypted, and the payload holds nothing else. - The message's
tsis the thread, andtargetis<channel>:<ts>. - The adapter then posts the instructions in the thread: "Reply in this thread to chat with the visitor. React with ✅ to the first message to end it."
chat.postMessage, message metadata
- Slack says metadata is readable by any member of the workspace.
- The visitor's messages go to the thread with
chat.postMessage(thread_ts), within Slack's limit of about 1 message per second per channel. A429gets one retry after itsRetry-After, within the request's deadline; otherwise the visitor sees a delivery error and can resend. - Replies:
messageevents in a thread (thread_ts≠ts).- Slack documents that
message_repliedevents lack theirsubtype, so the adapter detects replies bythread_ts. - Events with
bot_idare skipped, the adapter's own posts among them. So are edits, deletions and other subtypes, and files: a person's file isn't forwarded, and the adapter answers in the thread that files don't reach the visitor.
- Slack documents that
- Finding the
reffor a reply: a reply's event doesn't carry its parent's metadata. The adapter reads the parent once withconversations.history(latest=thread_ts,inclusive,limit: 1,include_all_metadata) and keepsthread_ts → refin a small per-instance cache. This is one read per thread per instance, not polling.conversations.repliesis never used. - Ending: a ✅ (
white_check_mark) reaction on the thread's first message, fromreaction_added(item.tsis the parent's).- Slash commands can't be run in threads and don't carry a
thread_ts(slash commands), so they can't end a specific chat. - A keyword reply ("end") was rejected: it is easy to type by accident.
- Slash commands can't be run in threads and don't carry a
- Verification:
X-Slack-Signatureisv0=plus HMAC-SHA256 with the signing secret overv0:<timestamp>:<raw body>, compared in constant time. Timestamps more than 5 minutes off are refused. The URL verification challenge is answered after the signature check.- Slack retries up to 3 times when it gets no 2xx within 3 seconds; the claimed
event_iddrops the duplicates. - Verifying requests, Events API
- Slack retries up to 3 times when it gets no 2xx within 3 seconds; the claimed
- Text, both ways:
- Into Slack: the visitor's text is escaped (
&,<,>only, as Slack documents), which makes<!channel>,<!here>and<@U…>inert. It goes withparse: 'none',mrkdwn: falseand nolink_names, and is cut at 4,000 characters (formatting). - Out of Slack:
<url|label>becomes[label](url)and<url>becomes the URL. User, channel and special mentions become plain text. Slack's&,<and>are decoded. The rest goes to the chat's Markdown sanitizer, at most 4,000 characters. - With
names: true, the adapter reads the person's display name withusers.info, which needsusers:read, and caches it per instance.
- Into Slack: the visitor's text is escaped (
9. HubSpot and Zendesk: one-way tickets
Both are plain onHandoff transports (ADR-0030 decision 5), written with fetch and no vendor SDK. Each throws on failure, so the handoff ends failed, or saved through onLead, within ADR-0030's ten seconds. The report carries the contact, the reason, the bot, the language and the content the bot allows (none, summary, transcript), in a plain-text description.
HubSpot (checked 2026-12-04):
- API:
POST /crm/objects/2026-09/tickets(create a ticket; dated versions ship in March and September with 18 months of support).- Properties:
subject,content,hs_pipelineandhs_pipeline_stage(internal IDs; the default pipeline when omitted), andhubspot_owner_idwhenowneris set. - The contact: upserted by email (
POST /crm/objects/2026-09/contacts/batch/upsertwithidProperty: 'email'), then associated inline with association type 16, ticket to contact.
- Properties:
- Idempotency: HubSpot has no idempotency header.
- The report's
idgoes in a ticket property created withhasUniqueValue: true(askdare_handoff_id), whichdoctorchecks. A retry then fails as a duplicate, and the adapter treats that as success. - h4 verifies that unique values work on tickets and what the duplicate error looks like. If they don't, it searches by the property before creating.
- The report's
- Authentication: a service key (Bearer), which HubSpot recommends now that legacy private apps can't be created (since 2026-10-26 for existing accounts; existing private app tokens keep working, and the same adapter takes either) (sunset, service keys).
- Scopes:
tickets(orcrm.objects.tickets.write),crm.objects.contacts.readandcrm.objects.contacts.write.
- Scopes:
- Plans: the scopes are available on any account, the free CRM included. Rate limits: 100 requests per 10 seconds on Free and Starter.
- Later: two-way chat through Custom Channels. Its scopes are listed for Sales or Service Hub Enterprise (the brief assumed Professional), and it needs an OAuth app.
Zendesk (checked 2026-12-04):
-
API:
POST /api/v2/tickets(tickets).requester: { name, email }from the report's contact, which creates the user depending on the account's settings.subject, acommentwith the plain-textbody,external_id(the report'sid, for people to search),tags(defaultaskdare, plus the reason), andgroup_id.- Without a contact, the ticket's requester is the authenticated agent, and the docs say so.
-
Idempotency: an
Idempotency-Keyheader with the report'sid. A repeat within 2 hours returns the first ticket (introduction), which covers ADR-0030's retries. -
Authentication: OAuth client credentials, not an API token. Zendesk deprecated API tokens:
- accounts created since 2026-07-28 can't use them;
- new tokens are blocked since 2026-10-27;
- all tokens stop working on 2027-04-30 (announcement).
The adapter takes
clientIdandclientSecretof a confidential OAuth client with thetickets:writescope (andusers:writeif requesters must be created). It exchanges them for a token (default 30 minutes; no refresh token) and caches the token per instance until shortly before it expires (OAuth migration). Zendesk attributes the tickets to the agent who created the client, so the docs recommend a dedicated agent with a restricted role. -
Plans: ticket creation through the API works on every plan, Support Team and Suite Team included. Rate limits: 200 requests a minute on Team plans.
-
Later: two-way chat through Sunshine Conversations, included from Suite Professional.
10. Packages: one add-on per vendor
@boldare/askdare-slack, @boldare/askdare-hubspot and @boldare/askdare-zendesk, like the other add-ons (-s3, -postgres, -upstash).
- Each vendor's API changes on its own calendar (HubSpot's dated versions, Zendesk's token sunset, Slack's rate limits), and a fix ships for that vendor alone.
- An app installs only the vendor it uses. Each is small, written with
fetchandnode:crypto, with no vendor SDK. - Each peers on
@boldare/askdareand imports only its public API, so a gap in the port becomes a core change (h1), not a private import. - First releases by hand, per
RELEASING.md.
11. The admin console
- The review (ADR-0032) shows a person's messages with their label and the live state lines, rebuilt from the notes as history is.
- The dashboard's handoff counts don't change. A live handoff counts once as delivered (
sent) when it reacheswaiting. Live, ended and missed aren't counted apart: they would need a new record kind, and "handoff and lead records in the admin store" is already under Later.
12. The threat model
New rows in THREAT_MODEL.md (numbers continue from T45):
-
T46, forged inbound events (
POST <basePath>/handoff/<name>). Defenses:receivechecks the vendor's signature (Slack: the signing secret's HMAC, constant-time) and timestamp window;- each event
idis claimed once for 10 minutes; - the body is capped at 64 KB, and requests are rate-limited per IP;
- the conversation is found only through
ref, sealed withCHAT_SECRETunder its owntyp, so a reference can't be forged or pointed at another bot.
What's left: anyone with the signing secret and a
ref(any workspace member can read the request message's metadata) can write into that conversation as the team. -
T47, a person's text reaching the visitor. It is rendered through the answers' Markdown sanitizer (no raw HTML, the link and image allowlists) and cut at 4,000 characters. Vendor markup is converted to plain Markdown first. What's left: a team member can send the visitor a link from the allowlist, as the bot's knowledge can.
-
T48, the visitor's text reaching the team's tool. Defenses:
- mentions and markup are escaped (Slack:
&,<,>; nolink_names;parse: 'none'); - live messages have their own per-visitor, per-IP and per-conversation limits, since each costs a person's attention;
- nothing a visitor types goes into a vendor field other than the message text and the report's documented fields.
What's left: visitor messages, contact details and the allowed content stay in Slack, HubSpot or Zendesk under that tool's retention.
docs/privacy.mdlists what each adapter sends, and the status line tells the visitor a person reads the chat. - mentions and markup are escaped (Slack:
-
T49, vendor credentials in the app's environment. The Slack bot token, Slack signing secret, HubSpot service key and Zendesk OAuth client are each read from the environment, use the fewest scopes, and appear in no log, error or report. Zendesk's tickets act as the client's agent, so the docs recommend a dedicated, restricted agent. What's left: a leaked Slack token can post wherever the bot is a member, a leaked HubSpot key can read and write contacts, and a leaked Zendesk client can create tickets.
13. What stays out
Typing indicators, files in live chat (either way), several people in one conversation, transferring between people, read receipts, a visitor's "End chat" button, push notifications to a closed tab, and business hours beyond available(). Two-way HubSpot and Zendesk are under Later (decision 9).
14. Order of work in 0.9
- h4 and h5 (HubSpot, Zendesk) need nothing from h1:
onHandoffexists since 0.7. They start once this ADR is accepted, onrelease/0.9, in the Add-ons lane. - h1 (server) after r1a (
bot/define-bot.ts,server/handler.ts) and e1 (protocol/*), with 0.8.x-p1 and p4 merged in. - h3 (Slack) after h1.
- h2 (chat) after h1, b1 and r1b. It changes
embed/host-events.tsafter r1c.
Consequences
-
New public API (ADR-0006, listed by z1):
handoff.liveindefineBot;liveChannelincreateChatHandler;LiveChannel,LiveEvent,LiveEndReason;memoryLiveChannelintesting;- the four states;
authorandnameon history messages;POST /live;- the new error code;
fromonmessage.received;- the
MessageAuthorprimitive and itsauthorpart; - five texts;
- three add-on packages.
All are additive: minor changesets.
-
The first inbound endpoint. Until now every request came from the visitor's browser. The Slack route is called by Slack and authenticated only by its signature.
/security-reviewruns on h1 and h3. -
Polling costs requests: about 20 a minute per visitor while a person is asked or writing and the page is visible, each one store read. On OpenAI Conversations, those count against the project's request rate limit.
-
A person's reply can take up to 15 seconds to show after a quiet minute.
-
A live chat's messages stay in the conversation, so later model calls read them, at input cost.
-
Slack keeps what the visitor wrote under the workspace's retention, and workspace members can read the request message's encrypted metadata.
-
Zendesk needs OAuth from day one, since its API tokens end on 2027-04-30. HubSpot needs a service key for new setups.
-
The React budget's room goes to live chat, after b1 frees it. The next feature that grows the chat makes room again (ADR-0028).
Alternatives considered
- A held SSE stream for replies, within
maxDuration, reconnecting. Push latency is better, but without pub/sub the server still reads the store in a loop, inside a function billed by duration. It needs reconnect and resume logic in the chat, which costs more bytes than a timer, and buffering proxies break it. Long-polling is the step to take if 3 seconds proves too slow. - Pub/sub through Upstash or Postgres
LISTEN. It would make live chat need a shared store beyond the conversation store, and wouldn't remove the reconnect problem on serverless hosts. - A lazy live chat chunk. Measured larger on first load in every case (see "What the prototype measured").
- A budget raise instead of b1. ADR-0028 decision 3 asks for room first, and 0.8-b1 showed 300 to 500 B can be found with the same behavior.
stopBot: false, where the bot keeps answering while a person is asked or writing. That makes two voices answering the same messages. The visitor who wants the bot back starts a new conversation, or waits formissed.- A person's message as a
developernote or ausermessage. A note gives the person's text developer authority, and that text can quote anything. Ausermessage puts it in the visitor's voice. - A new stored item kind for a person (
role: 'person'). It changes theConversationStoreport and every store's schema, and OpenAI's items have no such role. - A mapping store (thread to conversation) instead of a sealed reference. It needs storage askdare doesn't have, and the OpenAI store can't index by thread.
- Slack: a slash command or a keyword to end. Slash commands don't run in threads, and a keyword is typed by accident.
- Slack:
conversations.repliespolling. It is rate-limited for non-Marketplace distributed apps, and events are cheaper anyway. - One
@boldare/askdare-handoffpackage with subpaths. Its version would move for every vendor's change, and its dependencies would grow for all of them. - Plain text for a person's messages. It is safe, but needs a second rendering branch (bytes) and loses links. The Markdown sanitizer already handles untrusted text.
- Zendesk API tokens (the brief's plan). They end on 2027-04-30, and new accounts can't create them at all.
Settled with the maintainer (2026-12-04)
Accepted with every recommendation under "Open questions". So:
- Replies reach the chat by polling
POST /live. - The bot is silent from
waitinguntil the chat ends; there is nostopBotoption. - Four states,
missedincluded, withwaitMinutes: 10andidleMinutes: 30by default. - A person's messages are
assistantitems after an[askdare:live]note, rendered as sanitized Markdown. - b1 frees at least 350 B in the React entry and 200 B in the headless case; no lazy chunk; a raise only by its own ADR.
message.receivedgainsfrom: 'person', with the 5 B change to the loader's allowlist in h2.- Slack ends a chat with a ✅ reaction; people's names are off by default.
- Zendesk uses OAuth client credentials, and HubSpot a service key.
- One package per vendor.
- The console shows the live state in the review; dashboard counts are unchanged.
The maintainer also asked whether HubSpot and Zendesk can be tested for free. They can:
- HubSpot with a free developer test account;
- Zendesk with its 14-day trial, opened just before h5's smoke test.
Open questions (settled above)
Each had a recommendation, and the maintainer accepted them all.
- Replies by polling
POST /live(decision 4). Recommended: polling every 3 s, backing off to 15 s, while visible. Alternative: a held SSE stream. - The bot is silent from
waitinguntilendedormissed, with nostopBotoption (decision 2). Recommended: yes. Alternative:stopBotas the brief sketched, with the bot answering while waiting. - Four states,
missedincluded (decision 1), with defaultswaitMinutes: 10andidleMinutes: 30. Recommended: yes. Alternative: three states, withendedcovering "nobody joined". - A person's messages are
assistantitems after an[askdare:live]note, rendered as sanitized Markdown (decisions 3 and 7). Recommended: yes. - The budget: b1 frees ≥350 B in the entry and ≥200 B headless; no lazy chunk; a raise only by its own ADR if b1 fails (decision 7). Recommended: yes.
from: 'person'onmessage.received, with the 5 B loader allowlist change in h2 after r1c (decision 7). Recommended: yes. Alternative: no field, so the page can't tell a person's reply from the bot's answer.- Slack: ending with a ✅ reaction on the request message, and people's names off by default (decision 8). Recommended: yes.
- Zendesk with OAuth client credentials, HubSpot with a service key (decision 9), against the briefs' API token and private app. Recommended: yes, forced by the vendors' sunsets.
- One package per vendor (decision 10). Recommended: yes.
- The console shows the live state in the review; dashboard counts unchanged (decision 11). Recommended: yes.