Your app's endpoints as bot tools
Make your server app's own endpoints into tools a bot or workflow can call: declare them in .oalo/app.json, deploy, and check Oalo's signature.
A bot can call your server app's own endpoints while it chats: "where's my order?" becomes a call to your order lookup, answered from your data, as the signed-in user. You write the endpoint in your app, declare it once, and deploy.
Declaring them
In .oalo/app.json at the root of the repo:
{
"tools": [
{
"name": "order_status",
"description": "The status and delivery date of one of the signed-in user's orders",
"method": "POST",
"path": "/oalo/tools/order-status",
"input": { "order_id": "string" },
"user": "required"
}
]
}
name: what the bot calls it. Lowercase letters, digits and_.description: how the bot knows when to use it. Say what it returns and when it applies; this is the part that decides whether the bot reaches for it.method(defaultPOST) andpath: an endpoint on your app. AGETsends the input as the query string; anything else as a JSON body.input: field name to type (string,number,integer,boolean,object,array,any), or{"type", "required", "description"}. The same format as a callable workflow's.user:"required"refuses the call when the chat isn't signed in as one of your users (see The chat widget);"optional"(the default) sends the user when there is one.timeout_ms: 1,000 to 30,000, default 15,000.
Each deploy reads it: oalo deploy for the preview, oalo deploy --env prod for the live app. The deploy's output lists the tools it found; a file
that doesn't parse leaves them as they were and says why. A tool you remove
from the file is turned off.
Attaching one to a bot
The tools join the workspace's tool list. A bot can call one once it's attached: in the bot's Tools tab under Your apps' tools, or
oalo bots tools bot_ABC --add order_status
A bot that isn't published calls the app's preview; a published bot calls the live app. Both are called inside your Base at the app's own address, never over the internet.
From a workflow
A workflow calls an app tool like any tool, with a Run a tool step naming
it; no attaching needed. A live run calls the live app, and Try it calls
the preview. The user it sends is the run's contact's id in your app (the
external_ref your app gave them through createChatSession or an app
event), empty when the contact didn't come from your app. Only the fields the
tool declares are sent, whatever else the step's input carries.
Checking the call is Oalo's
Your endpoint is a normal route, so anyone could send it a request. Each call from a bot carries:
| Header | |
|---|---|
X-Oalo-User | your own id for the signed-in user (the external_ref you gave createChatSession), empty when the chat is anonymous |
X-Oalo-Tool, X-Oalo-Bot, X-Oalo-Conversation | which tool, which bot (public id), which conversation (empty from a workflow) |
X-Oalo-Workflow | the workflow's name, when a workflow called it |
X-Oalo-Timestamp, X-Oalo-Signature | v1= and a hex HMAC-SHA256, with the app's own OALO_SYNC_TOKEN as the key, over the timestamp, method, path (with query), user and raw body, joined by newlines |
oalo typegen gives you verifyOaloToolCall, which checks it and returns who
the call is for. Pass the raw body, before JSON parsing:
import { verifyOaloToolCall } from "./oalo.generated";
app.post("/oalo/tools/order-status", express.text({ type: "*/*" }), async (req, res) => {
const call = await verifyOaloToolCall({ method: req.method, path: req.originalUrl, headers: req.headers, body: req.body })
.catch(() => null);
if (!call?.user) return res.status(401).end();
const { order_id } = JSON.parse(req.body);
res.json(await orders.statusFor(call.user, order_id));
});
- Trust
call.user, never the input, for whose data to read: the input comes from the conversation, which the user can steer. - Calls older than five minutes are refused.
- The key is per env, like the token: the preview's calls are signed with the
preview's token. Rotating the token (
oalo env rotate-token) changes it for both sides at once.
Webhooks to other servers
A webhook tool on a bot, or a workflow's Send webhook step, posts to any address you give it, not only your app. Every one of those requests is signed too, whatever key you set on the webhook (a bearer token or HMAC):
| Header | |
|---|---|
Oalo-Signature | t=<unix seconds>,v1=<hex HMAC-SHA256> of "<t>.<raw body>", keyed with your workspace's signing secret |
The secret (whsec_...) is in Settings > Sync API > Webhooks, under
"Signing secret for webhooks your bots and workflows send". Admins can show
it and rotate it there. It's the same check as for event webhooks: recompute
the HMAC over the raw body, compare, and refuse a t older than five
minutes. A header a workflow sets itself can't replace it.
const [, t, v1] = req.get("oalo-signature").match(/^t=(\d+),v1=([0-9a-f]+)$/);
const want = crypto.createHmac("sha256", process.env.OALO_WEBHOOK_SECRET).update(`${t}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
if (!fresh || !crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(want))) return res.status(401).end();
What the bot gets back
Your endpoint's JSON (or text), up to 20 KB. A non-2xx answer reaches the bot as an error with your status and the start of your body, so it can tell the user something went wrong. Keep answers small and to the point: the bot reads all of it.
Common mistakes
- Parsing the body before checking the signature. The signature covers the exact bytes sent.
- A vague description. The bot won't call a tool it can't tell it needs.
- Reading the user from the input. Use
call.user. - A tool only in the preview. A published bot calls the live app, which has the tools of its last live deploy.
Put a bot on any web page with one script tag, anonymous or signed in as your app's own user through POST /api/chat/v1/sessions.
Call a workflow from your app's server like a function, POST /api/workflows/v1/<name>/run, and get back what its Output step returns.
Give an app its API keys and settings with oalo env, per env: what is secret, what each kind of app gets, its own token and database, and when changes apply.
The six kinds of credential in Oalo, what each one is for, how to create it, and which ones are safe to put in an app.
Sign up, install the CLI, and deploy your repo in a few minutes.