Build a context plugin
A context plugin is one HTTPS endpoint on your side. Inboxen posts a customer’s email address to it, signed with a secret only you and Inboxen know. Your endpoint answers with labelled fields, which agents see in the customer sidebar. Fields you mark as AI-visible can also go into AI drafts.
- When Inboxen calls: an agent opens a conversation with the plugin’s panel open, an agent clicks Try again, AI prepares a draft, or an owner or admin clicks Test. Each call is about one address.
- What is sent:
{"version": 1, "email": "…"}and nothing else. - How it is secured: an HMAC-SHA256 signature over the body and a timestamp, as Standard Webhooks specifies. The secret is never sent.
- What you send back: sections of labelled fields. You decide for each field whether AI drafts may read it.
- Version: contract version 1. Actions (buttons for agents) are accepted in the answer but not offered to agents yet.
Connect it in Inboxen
Section titled “Connect it in Inboxen”An owner or admin of the brand sets the plugin up under Settings › Context plugins. Context plugins are part of the Business plan. On other plans Inboxen doesn’t call a plugin, and Test is refused.
- Click Add a plugin and enter the endpoint, for example
https://api.example.com/inboxen/context. - Under Signing secret, click Generate a secret and copy it. Inboxen shows it only once.
- Add the same secret to your endpoint’s configuration.
- Click Add plugin, then enter a customer’s address under Look up an address and click Test. You see the panel as an agent would.
Inboxen refuses an endpoint that:
- is not
https; - contains a user name or password;
- has a
?or#part (the address travels in the signed body, not the URL); - is a private, loopback or link-local address, or resolves to one. This is checked again on every call.
After saving, Inboxen shows only the secret’s last four characters. Changing the endpoint deletes the stored secret, so enter it again.
The request
Section titled “The request”Inboxen sends one POST per lookup, with a JSON body and three signature headers.
POST /inboxen/context HTTP/1.1Host: api.example.comContent-Type: application/jsonAccept: application/jsonUser-Agent: Inboxen-ContextPlugin/1webhook-id: msg_6f1c2a9e-3b7d-4e1a-9c0f-2d8e5b4a7c11webhook-timestamp: 1792310400webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
{"version":1,"email":"jan@example.com"}| Part | Value | Your endpoint should |
|---|---|---|
webhook-id |
msg_ and a UUID, new for every request |
Refuse an id it has already seen |
webhook-timestamp |
Unix seconds when Inboxen signed the request | Refuse it when more than 5 minutes off your clock |
webhook-signature |
v1, and a Base64 HMAC-SHA256 |
Verify it before reading the body |
version |
Always 1 for this contract |
Answer 400 for any other value |
email |
The customer’s main address in Inboxen | Trim and lower-case it before the lookup |
Treat email as untrusted input even after the signature checks out: validate it as an address and use it only as a lookup key.
Verify each request
Section titled “Verify each request”Accept a request only when its signature matches one of your secrets and its timestamp is within 5 minutes. Answer 401 otherwise, before looking anyone up. Any Standard Webhooks library does this for you. If you write it yourself:
- All three headers are required. A missing one is a
401. - Read
webhook-timestampas Unix seconds. Refuse it when it is more than 300 seconds before or after your clock. - The HMAC key is the Base64-decoded bytes after
whsec_, not the text of the secret. - Sign
webhook-id + "." + webhook-timestamp + "." + body, with the body bytes exactly as received, before any JSON parsing. webhook-signaturecan hold several values separated by spaces. Accept the request when anyv1,value matches.- Compare in constant time.
- Try each of your secrets, so an old and a new one can overlap while you rotate.
Java, with the JDK only:
public final class InboxenSignatureVerifier {
private static final long TOLERANCE_SECONDS = 5 * 60;
private final List<byte[]> keys;
public InboxenSignatureVerifier(List<String> secrets) { this.keys = secrets.stream() .map(String::strip) .filter(s -> s.startsWith("whsec_")) .map(s -> Base64.getDecoder().decode(s.substring("whsec_".length()))) .toList(); }
public boolean verify(String id, String timestamp, String signatureHeader, byte[] rawBody, Instant now) { if (id == null || id.isBlank() || timestamp == null || signatureHeader == null) { return false; } long ts; try { ts = Long.parseLong(timestamp); } catch (NumberFormatException e) { return false; } if (Math.abs(now.getEpochSecond() - ts) > TOLERANCE_SECONDS) { return false; } byte[] signedPrefix = (id + "." + timestamp + ".").getBytes(StandardCharsets.UTF_8); for (byte[] key : keys) { byte[] expected = hmac(key, signedPrefix, rawBody); for (String candidate : signatureHeader.split(" ")) { if (!candidate.startsWith("v1,")) { continue; } byte[] given; try { given = Base64.getDecoder().decode(candidate.substring(3)); } catch (IllegalArgumentException e) { continue; } if (MessageDigest.isEqual(expected, given)) { return true; } } } return false; }
private static byte[] hmac(byte[] key, byte[] signedPrefix, byte[] body) { try { Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(key, "HmacSHA256")); mac.update(signedPrefix); return mac.doFinal(body); } catch (GeneralSecurityException e) { throw new IllegalStateException("HmacSHA256 is unavailable", e); } }}TypeScript, for Node or Bun:
import { createHmac, timingSafeEqual } from 'node:crypto'
const TOLERANCE_SECONDS = 5 * 60
export function verify( secrets: string[], headers: { id?: string; timestamp?: string; signature?: string }, rawBody: Buffer, nowSeconds = Math.floor(Date.now() / 1000),): boolean { const { id, timestamp, signature } = headers if (!id || !timestamp || !signature) return false const ts = Number(timestamp) if (!Number.isInteger(ts) || Math.abs(nowSeconds - ts) > TOLERANCE_SECONDS) return false for (const secret of secrets) { if (!secret.startsWith('whsec_')) continue const key = Buffer.from(secret.slice('whsec_'.length), 'base64') const expected = createHmac('sha256', key).update(`${id}.${timestamp}.`).update(rawBody).digest() for (const candidate of signature.split(' ')) { if (!candidate.startsWith('v1,')) continue const given = Buffer.from(candidate.slice(3), 'base64') if (given.length === expected.length && timingSafeEqual(given, expected)) return true } } return false}Test vector, from the Standard Webhooks specification: secret whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw, id msg_p5jXN8AQM9LWM0D4loKWxJek, timestamp 1614265330 and body {"test": 2432232314} give v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=.
Replays. Keep the webhook-id values you have seen in the last 10 minutes, for example in Redis with an expiry, and answer 401 to a repeat. Inboxen sends a new id with every call.
Secrets. Keep them in a secret store or an environment variable, never in your repository. If your service has other API keys, keep the Inboxen secrets in a list of their own, so a key for one route can never open another.
Rotation.
- In Inboxen, edit the plugin and click Generate a secret. Copy it, but don’t save yet.
- Add the new secret to your endpoint next to the old one and deploy.
- Save the plugin in Inboxen and click Test.
- Remove the old secret from your endpoint and deploy.
The answer
Section titled “The answer”Answer 200 with Content-Type: application/json: a title, sections of labelled fields, and an optional list of actions.
{ "title": "Example Shop", "sections": [ { "label": "Account", "fields": [ {"label": "Plan", "value": "Pro", "ai_visible": true}, {"label": "Customer since", "value": "2024-01-01", "ai_visible": true}, {"label": "Orders", "value": 12, "link": "https://shop.example.com/admin/customers/42"} ] } ], "actions": []}When you have no customer at the address, answer 404, or 200 with {"found": false}. Neither counts as a failure.
| Key | Type | Rule |
|---|---|---|
title |
text | The panel’s title, at most 80 characters |
sections[].label |
text | At most 80 characters |
sections[].fields[].label |
text | Required; a field without one is left out |
sections[].fields[].value |
text, number, or true or false | Shown as text, at most 500 characters |
sections[].fields[].link |
text | An absolute https:// or http:// address without a user name or password, or it is dropped |
sections[].fields[].ai_visible |
true or false | Only JSON true lets AI drafts read the field; a missing key, "true" or 1 keeps it hidden |
actions[] |
{id, label} |
id is lower-case letters, digits, _, . and -, up to 64 characters; not offered to agents yet |
Limits. The answer is at most 64 KB, or the call fails. Beyond that Inboxen shortens rather than fails: at most 12 sections, 40 fields in a section, 120 fields in all and 8 actions. Longer text is cut and ends in …. Control and text-direction characters are removed, unknown keys are ignored, and nothing is shown as HTML.
Choosing what AI may read. Mark a field ai_visible only when a reply to the customer may mention it. A good rule: what the customer can see in their own account is fine; staff-only notes, admin links, internal ids, other people’s details and commercial terms are not. Links never reach a draft, even on an AI-visible field.
Keep the answer lean. Every field is shown to every agent who can see the customer. Leave out secrets, tokens, password hashes, payment details and anything else agents don’t need; hiding a field from AI is not enough.
Timeouts and failures
Section titled “Timeouts and failures”Your endpoint has 2 seconds for the whole call: connecting, TLS and the full answer. Aim for well under 500 ms, because agents wait for it.
| Your answer | What Inboxen does |
|---|---|
200 with sections |
Shows the panel |
404, or 200 with {"found": false} or no sections |
Shows that there is no record for the address |
401 or 403 |
Fails, and the plugin’s card asks you to check the signing secret |
408, 429 or 5xx |
Fails, as down or overloaded |
3xx |
Fails without following the redirect; enter the final address as the endpoint |
| Any other status | Fails, as an error answer |
| Not JSON, not an object, or over 64 KB | Fails, and the card asks you to check what the endpoint sends back |
| No full answer within 2 s | Fails, as no answer in time |
- No automatic retries. An agent can click Try again.
- Pause after failures. After 5 failed calls in a row, Inboxen stops asking for a minute, then tries one call.
- Reuse. An answer is reused for 5 minutes per address. While your endpoint is down, agents see the last answer for up to an hour, marked with its age. AI drafts never use an answer older than 5 minutes.
Answer 400 to a malformed body or another version, and 401 to any signature problem. Keep error bodies empty: don’t say which check failed or which secret was tried.
Security checklist
Section titled “Security checklist”Anyone with your secret can look up any of your customers by email address, so guard it like a database password.
- The endpoint is served over HTTPS with a valid public certificate, and never redirects.
- The signature and timestamp are checked before the body is parsed or anyone is looked up.
- Every signature failure answers
401with the same empty body. - Signatures are compared in constant time.
- Secrets come from a secret store or the environment, in a list of their own.
- Two secrets can be active at once, for rotation.
- A
webhook-idseen in the last 10 minutes is refused. -
emailis validated, trimmed and lower-cased, and used only as a lookup key in a parameterised query. - The answer carries no secrets, tokens, password hashes, payment details or other customers’ details.
- Only fields a reply may mention are marked
ai_visible. - Links lead to pages that require their own sign-in.
- Logs carry the
webhook-idand the outcome, never the email address, the secret or the signature. - A rate limit applies to the endpoint, for example 60 requests a minute, in case a secret leaks.
- Your privacy records list this flow: customer email addresses sent from Inboxen to your endpoint.
Test your endpoint
Section titled “Test your endpoint”Before you connect Inboxen, cover these cases:
| Case | Expected |
|---|---|
| Known customer, valid signature | 200 with sections |
| Unknown address | 404 or {"found": false} |
| Address in other case or with spaces around it | The same customer as the lower-case address |
No email, or a version other than 1 |
400 |
| One of the three headers missing | 401 |
| Wrong secret, or the body changed after signing | 401 |
| Timestamp 6 minutes old or 6 minutes ahead | 401 |
The same webhook-id twice |
401 the second time |
| Old and new secret during a rotation | 200 for both |
| The answer | No secrets; no field marked ai_visible that should be hidden |
| Your logs | No email address or signature |
To send a signed request by hand:
SECRET='whsec_...'ID="msg_$(uuidgen)"TS=$(date +%s)BODY='{"version":1,"email":"jan@example.com"}'KEY_HEX=$(printf '%s' "${SECRET#whsec_}" | base64 -d | od -An -tx1 | tr -d ' \n')SIG=$(printf '%s' "$ID.$TS.$BODY" | openssl dgst -sha256 -mac HMAC -macopt hexkey:$KEY_HEX -binary | base64)curl -i https://api.example.com/inboxen/context \ -H 'Content-Type: application/json' \ -H "webhook-id: $ID" -H "webhook-timestamp: $TS" -H "webhook-signature: v1,$SIG" \ --data-raw "$BODY"Then connect it in Inboxen, click Test with a known address, and open a conversation from that customer to see the panel in the sidebar.
For help building a plugin, write to support@inboxen.net.