ReplyBrain Docs LLMs

Events

Your app tells ReplyBrain what happens in its help desk by posting events to POST https://replybrain.com/v1/connections/{connection_id}/events, signed with the connection's secret (see Connection events for the signature). With the gem:

ReplyBrain::Client.connection.post_event(event_hash)   # signed for you

A complete event

{
  "source_event_id": "message:88",
  "source_object": { "type": "ticket", "id": "SUP-1042" },
  "source_revision": "14",
  "occurred_at": "2026-11-12T09:30:00Z",
  "kind": "conversation.message_added",
  "message": {
    "id": "88",
    "visibility": "customer",
    "direction": "inbound",
    "channel": "in_app",
    "author": "requester",
    "body_text": "My export has been stuck since this morning."
  },
  "requester": {
    "ref": "user:42",
    "account_scope": "42",
    "name": "Ada",
    "email": "[email protected]",
    "avatar_url": "https://example.com/avatars/42.jpg"
  },
  "assignee": {}
}

Fields

Field Required Meaning
source_event_id yes (or source_revision) Unique per event. The deduplication key.
source_object yes { type, id } of the conversation. Every event with the same pair is the same conversation.
source_revision no Your revision of the conversation. Without source_event_id, the identity is type:id:revision:kind.
occurred_at yes ISO 8601, when it happened in your app.
kind yes conversation.message_added, conversation.opened, conversation.reopened, conversation.closed, conversation.assigned.
message.id recommended Your id for the message (else source_event_id is used).
message.visibility yes, in practice customer or internal. Missing means internal, and internal messages are never answered.
message.direction no inbound (default) or outbound.
message.channel yes, in practice email, in_app, whatsapp, sms, phone or api. Fixed when the conversation is first seen. Missing (or unknown) means api.
message.body_text yes for a message Plain text.
message.author no requester or agent.
message.author_name no On an outbound agent message, the teammate's name as the customer reads it (up to 60 characters). The console's thread shows it as who sent that reply.
message.author_email no On an outbound agent message, the address that teammate signs in with. When it is a member of your ReplyBrain team's, the reply is that member's: the thread shows their name and avatar there. Anyone else's is ignored.
requester.ref yes for a requester Your stable id for the customer. Without it, the rest of requester is ignored.
requester.account_scope no Your id for their account: what facts requests carry back.
requester.name, email, phone no Your word about them. An email is kept unverified and is never written to; a phone is used only in E.164 (+34600000000).
requester.avatar_url no Where you keep their picture: an https address, up to 2,048 characters. The console draws it beside their name; ReplyBrain stores the address, never the image, and the AI agent never reads it. Kept as you said it last: an event without it removes the picture.
requester.session no { verified: true, method, provenance, verified_at, expires_at }, only on an inbound message your server verified the signed-in customer posted. Binds the case to the account.
assignee no { name, email } of the teammate holding the ticket, {} for nobody. See [[concepts/ticket-holder
caused_by_action_id no When the event echoes ReplyBrain's own work: the publication_id (or action id) it sent you.

Bodies over 256 KB are refused. A body without source_object, kind or a valid occurred_at, or without any identity, is 400 and nothing is recorded.

Idempotency: one event, once

Events are recorded once per (connection, source_event_id). Posting the same id again answers 202 with "state": "duplicate" and changes nothing, even if the body is different.

WARNING

To correct something you already sent (a wrong channel, a missing assignee), post a new event with a new source_event_id. Re-posting the old id with a fixed body is silently ignored. And a conversation's channel is fixed when it is first seen: a later event cannot move it.

Use ids derived from your own records (message:88, assigned:SUP-1042:2026-11-12T09:31:00Z), so a retry after a timeout sends the same id and is harmless.

Ordering

Post from a job enqueued after your transaction commits, one per event, and retry it on failure. Events may arrive out of order: open/closed status and the holder follow occurred_at, so an older event never overwrites what a newer one said. A backstop sweep that re-posts recent events (same ids) repairs anything a crashed job missed.

What an event triggers

  • Every event updates the conversation's open/closed status (from its kind) and its holder (from assignee).
  • A customer-visible message is linked to its case.
  • A new inbound message is taken in: it may be drafted, routed to a person, or both. Outbound messages, your echoes of ReplyBrain's own drafts and backfilled history are recorded and nothing more.

Backfill

If your app defines backfill on its source, ReplyBrain can replay history after a cursor: POST /replybrain/events/backfill with { "after": "<cursor>" }, answered with { "events": [ ... ] }, each event body with its own cursor. Backfilled events are recorded with no effect: no drafts, no needs.

class HelpDeskSource < ReplyBrain::Client::Source
  backfill do |after|
    HelpDeskEvent.after(after).limit(100).map { |e| e.to_replybrain.merge(cursor: e.id.to_s) }
  end
end