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

  • Twilio providers different events for each product — Voice, SMS, Conversations, Sync, Authy, Chat, and Autopilot. The full list of events for each product is available in its Official Doc ↗

Security Headers

  • Signature Header: X-Twilio-Signature
  • Hash: sha1
  • Encode: base64
  • payload: hash

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" })
  }
})