A minimal support agent: when an email arrives, an LLM drafts a reply and Sentvia sends it back
in the same thread. The pattern is webhook → generate → reply.
1. Register a webhook
curl -X POST https://api.sentvia.ai/v1/webhooks \
-H "Authorization: Bearer sv_live_…" -H "Content-Type: application/json" \
-d '{ "url": "https://your-app.com/sentvia", "events": ["message.received"] }'
Store the returned signing secret.
2. Handle inbound and reply
import crypto from "node:crypto";
const KEY = process.env.SENTVIA_KEY!;
const SECRET = process.env.SENTVIA_WEBHOOK_SECRET!;
const API = "https://api.sentvia.ai/v1";
// Express-style handler. Use the RAW body for signature verification.
export async function handler(req, res) {
const sig = req.headers["x-sentvia-signature"];
const expected = "sha256=" + crypto.createHmac("sha256", SECRET).update(req.rawBody).digest("hex");
if (sig !== expected) return res.status(401).end();
const { event, message } = JSON.parse(req.rawBody);
if (event !== "message.received") return res.status(200).end();
// 1. draft a reply with your LLM of choice
const reply = await draftReply(message.subject, message.body_text);
// 2. send it in-thread
await fetch(`${API}/messages/${message.id}/reply`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ text: reply }),
});
res.status(200).end(); // respond fast; do heavy work async
}
Replies thread automatically — Sentvia sets In-Reply-To/References and prefixes the subject
with Re:. No need to track headers yourself.
Going further
- Add a block list rule so the agent ignores known spammers.
- Use the realtime WebSocket instead of (or alongside) webhooks for a live view.
- Want native tools instead of REST? Connect via MCP.