Connection Events
POST https://replybrain.com/v1/connections/{connection_id}/events
Your app posts its help desk's events here. No API key: the request is signed with the connection's secret. The body is described field by field in Events.
Signing
ReplyBrain-Signature: t=<unix seconds>,v2=<hex HMAC-SHA256(secret, signed string)>
ReplyBrain-Key-Id: <key id, e.g. key_1>
Content-Type: application/json
signed string = "v2" \n t \n "POST" \n path \n connection_id \n raw body
pathis the request path exactly as sent:/v1/connections/<connection_id>/events, plus?queryif you add one.raw bodyis the exact bytes you send. Serialize once, sign those bytes, send those bytes.- The timestamp must be within five minutes of ReplyBrain's clock.
- The key id must be the connection's current or previous key.
Ruby, by hand
require "openssl"
require "json"
require "net/http"
body = JSON.generate(event)
path = "/v1/connections/#{connection_id}/events"
t = Time.now.to_i
signature = OpenSSL::HMAC.hexdigest("SHA256", secret, ["v2", t, "POST", path, connection_id, body].join("\n"))
request = Net::HTTP::Post.new(path, "Content-Type" => "application/json",
"ReplyBrain-Signature" => "t=#{t},v2=#{signature}", "ReplyBrain-Key-Id" => key_id)
request.body = body
uri = URI("https://replybrain.com")
Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
With the gem it is one line: ReplyBrain::Client.connection.post_event(event).
Node
import crypto from "node:crypto";
const body = JSON.stringify(event);
const path = `/v1/connections/${connectionId}/events`;
const t = Math.floor(Date.now() / 1000);
const v2 = crypto.createHmac("sha256", secret).update(["v2", t, "POST", path, connectionId, body].join("\n")).digest("hex");
await fetch(`https://replybrain.com${path}`, {
method: "POST",
headers: { "Content-Type": "application/json", "ReplyBrain-Signature": `t=${t},v2=${v2}`, "ReplyBrain-Key-Id": keyId },
body,
});
Answers
| Status | Body | Meaning |
|---|---|---|
202 |
{ "object": "source_event", "id", "connection_id", "source_event_id", "state": "recorded" } |
Recorded. Drafting happens afterwards. |
202 |
the same, "state": "duplicate" |
This source_event_id was already recorded. Nothing changed. |
400 |
invalid_request |
Not JSON, or the event has no source_object, kind, valid occurred_at or identity (details.reason). |
401 |
unauthenticated |
The signature is missing, expired, signed with an unknown key, or does not match. |
404 |
not_found |
No such connection. |
413 |
invalid_request |
The body is over 256 KB. |
TIP
Treat any 202 as done, and retry anything else with the same body and source_event_id (re-signed with a fresh timestamp). Because events are deduplicated by source_event_id, a retry that already landed answers duplicate.
The calls ReplyBrain makes to your app
They are signed the same way, with your mount in the path (/replybrain/facts/order) and your connection_id as the audience. Your app must verify every one and refuse anything else with 401. The interactive reference lists them as webhooks; Capabilities explains each.