Webhook handler factory, structured extraction per inbox, and full SMS support.
New in v0.2.0
Webhook handler factory
import { createWebhookHandler, verifyCommuneWebhook } from 'commune-ai';
const handler = createWebhookHandler({
verify: ({ rawBody, headers }) => verifyCommuneWebhook({
rawBody,
timestamp: headers["x-commune-timestamp"] as string,
signature: headers["x-commune-signature"] as string,
secret: process.env.COMMUNE_WEBHOOK_SECRET!,
}),
onEvent: async (message, context) => {
// message is typed UnifiedMessage
// context.payload has inboxId, domainId, extractedData
const reply = await agent.process(message.content);
await client.messages.send({ to: sender, text: reply, thread_id: message.thread_id, inboxId: context.payload.inboxId });
},
});Structured extraction in webhook payload
When you've set a schema on an inbox, the extractedData field is populated in the webhook context:
onEvent: async (message, context) => {
const { issueType, urgency, orderId } = context.payload.extractedData ?? {};
// Route without an extra LLM call
}SMS
const phone = await client.phoneNumbers.provision();
await client.sms.send({ to: "+14155551234", body: "Shipped!", phoneNumberId: phone.id });