Tutorial: Webhook Automation
10-minute tutorial to automate Vant with webhooks
What You’ll Build
Two real automation surfaces:
- Webhook server -
lib/webhooks.js: an inbound HTTP receiver for HMAC-signed custom routes (vant webhooks) - Scheduled jobs - interval timers via
vant.cron(brain prune, sync)
No prebuilt GitHub-push route ships - the server takes routes YOU register. To sync on GitHub activity, use vant watch (polling) or the scheduler below.
Why Webhooks?
- Notify external tools when brain events happen
- Schedule brain cleanup on a timer
- Keep GitHub in sync without manual pushes
Webhook Server (Vant’s)
Vant ships its own webhook system (bin/webhooks.js + lib/webhooks.js), serving on port 3467 by default. It is an INTAKE: custom routes register via the library (register({ name, source, secret, dispatch, ... })), requests POST to <url>/<source> with an HMAC signature header, and the ack honestly reports { received, event, source, handlers, dispatched }
- identical signed bytes replay as 409 (the dedupe is DURABLE: a fleet-grade JSON ledger per brain -
VANT_WEBHOOK_REPLAY_LEDGERoverride; retention TTL default 24h viawebhookReplayTtlMs, one-week ceiling), stale envelopes refuse 401 (5-minute ts window on timed sources). GET /info/<name>returns NON-SECRET route metadata only, and CORS echoes an origin only from the explicit opt-in list (VANT_WEBHOOK_CORS_ORIGINS; default empty = no browser cross-origin access).
The CLI manages the outbound/side list:
vant webhooks list # registered hooks
vant webhooks add <url> <event> # register a target URL + event
vant webhooks remove <id> # unregister by hook id
vant webhooks test <id> # fire a test payload
Required env:
VANT_WEBHOOK_SECRET=xxx # the route refuses to bind without a secret
VANT_WEBHOOK_PORT=3467 # optional (default 3467)
VANT_WEBHOOK_BIND=127.0.0.1 # default loopback; set deliberately to widen
Crew-bus events are also emitted as webhook:crew.<type> events you can subscribe to in-process.
Scheduled Jobs
Use cron - schedules are interval timers in milliseconds (1000-86400000), not cron expressions:
const cron = require('vant-os').cron;
// Hourly sync
const sync = require('./lib/sync');
cron.schedule({
id: 'hourly-push',
interval: 3600000,
handler: async () => {
await sync.pushAll();
console.log('Synced to GitHub');
}
});
For pruning, use the real prune CLI on a schedule outside the process (cron tab or your scheduler of choice):
# Daily prune at 2am (system crontab)
0 2 * * * cd /path/to/vant && vant prune --stale-days=14 --force
(flags are =-joined, and --force is what takes it out of the default dry run)
Custom Webhooks
Trigger Agent Action
const vant = require('vant-os');
const sync = require('./lib/sync');
const { commit } = require('./lib/branch');
app.post('/webhook/trigger', async (req, res) => {
const { action, params } = req.body;
switch (action) {
case 'learn':
await vant.learn(params.key, params.content);
break;
case 'search':
const results = await vant.think(params.query);
return res.json(results);
case 'commit':
await commit('MyAgent', params.message);
break;
case 'sync':
await sync.pushAll();
break;
}
res.json({ success: true });
});
Usage
# Learn something
curl -X POST https://your-domain.com/webhook/trigger \
-H "Content-Type: application/json" \
-d '{"action": "learn", "params": {"key": "test", "content": "Learned something!"}}'
# Search brain
curl -X POST https://your-domain.com/webhook/trigger \
-H "Content-Type: application/json" \
-d '{"action": "search", "params": {"query": "python"}}'
Security
Verify GitHub Signature
const crypto = require('crypto');
function verifyGitHubSignature(payload, signature) {
const hmac = crypto.createHmac('sha256', WEBHOOK_SECRET);
const digest = 'sha256=' + hmac.update(payload).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(digest)
);
}
app.post('/webhook', (req, res) => {
const signature = req.headers['x-hub-signature-256'];
if (!verifyGitHubSignature(JSON.stringify(req.body), signature)) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process webhook
});
API Key
const API_KEY = process.env.WEBHOOK_API_KEY;
app.post('/webhook/trigger', (req, res) => {
const key = req.headers['x-api-key'];
if (key !== API_KEY) {
return res.status(401).json({ error: 'Invalid API key' });
}
// Process request
});
Use Cases
GitHub Push -> Sync
Vant polls GitHub itself - run the watcher rather than a receiver:
vant watch --interval 30 # poll for changes every 30s
Linear Issue -> Learn
// On issue created, learn from it
app.post('/webhook/linear', async (req, res) => {
const { issue } = req.body;
await vant.learn('issues/' + issue.id, issue.description);
});
Cron -> Prune
# Daily brain cleanup (system crontab)
0 2 * * * cd /path/to/vant && vant prune --force