Skip to content
Start free

Hosted functions

Hosted functions are project-scoped TypeScript handlers hosted by Wabery. Use them when a WhatsApp workflow needs server-side logic close to the conversation: quote calculators, order lookups, enrichment, routing decisions, or small tools that a Business Agent can call.

Functions are created as metadata first, then deployed from source. A function must be active and have a successful deployment before Wabery can invoke it.

Terminal window
wabery functions create \
--slug quote-customer \
--name "Quote customer" \
--trigger-type ANY_MESSAGE
wabery functions deploy fn_... --source ./quote-customer.ts
wabery functions test fn_... --text "Can you quote this?"
wabery functions logs fn_...

trigger_type matches automation triggers: KEYWORD, WELCOME, or ANY_MESSAGE.

Export a default async handler. Wabery passes the normalized event and a scoped context object.

export default async function handler(event, ctx) {
const profile = await ctx.data.get("profile");
await ctx.kv.put("last_event", event.type);
ctx.log("message", event.text);
return {
ok: true,
profile,
};
}

Context access is scoped to the authenticated project and contact. Functions are request/response handlers; keep them bounded and use logs for debugging rather than long-running work.

Hosted functions can back a Meta Business Agent connector tool, or be exposed as an external MCP/tool call. External invocation is opt-in:

Terminal window
wabery functions update fn_... \
--expose-as-mcp-tool true \
--input-schema '{"type":"object","properties":{"orderId":{"type":"string"}}}'
wabery functions invoke fn_... --arguments '{"orderId":"ord_123"}'

SDK equivalent:

await wabery.functions.update("fn_...", {
exposeAsMcpTool: true,
inputSchema: {
type: "object",
properties: { orderId: { type: "string" } },
},
});
await wabery.functions.invoke("fn_...", {
arguments: { orderId: "ord_123" },
});

To wire a Business Agent tool to hosted logic, create a connector tool with backing_type: "HOSTED_FUNCTION" and backing_function_id: "fn_...".

Use scoped API keys where possible:

Scope Allows
functions:read List functions, fetch source, read invocation logs.
functions:write Create, update, deploy, test, and delete functions.
functions:invoke Invoke an exposed function as a tool.

The CLI and MCP server use the same REST endpoints. MCP write tools require write mode and confirmation tokens for create, deploy, update, invoke, and delete actions.