Twilio Webhook Specs, Events, and Examples
Twilio uses webhooks to notify third-party apps of events in its main products including voice calls initiated, SMS messages sent, and dialogs started in autopilot. You can wire Twilio events to trigger action in third-party apps such as record when someone responds to an SMS message.
Specifications | |
Supported Events |
|
Security Headers |
|
Documentation | |
SDKs and Sample Code |
Sample Validation
const crypto = require('crypto')
const sigHeader = 'X-Twilio-Signature'
const hashAlgo = 'sha1'
const encode = 'base64'
const hmacSecret = process.env.WEBHOOK_SECRET
app.post('/twilio-webhook', (req, res) => {
//01: Validate signature
const message = req.body
const digest = crypto.createHmac(hashAlgo, hmacSecret)
.update(message).digest(encode)
if (request.headers[sigHeader] !== digest) {
res.status(401).send('Request unauthorized')
}else{
//02: Process message
res.json({ message: "Success" })
}
})