Twilio webhooks: usage spikes and Debugger errors as signals
Point Twilio's usage triggers and Debugger webhook at a Pulso webhook source, checked with your account's signature, and turn spend spikes and delivery errors into signals with a playbook.
Twilio bills by use, so a bug or an SMS pumping attack shows up first as spend. Usage triggers call a URL when a usage category passes a value you set, and the Debugger calls one for each error it logs. Point both at a Pulso webhook source and each becomes a signal with the steps to follow.
Connect Twilio#
Add Twilio to Pulso to create a webhook source called Twilio; it shows these steps with the source’s URL and takes your Auth Token to check signatures, then creates the monitors below that you pick, with their playbooks and a report. To start from scratch instead, create a webhook data source called Twilio.
- In the Twilio Console, copy the Auth Token under Account Info and paste it as the source’s signing secret: below these steps in Add to Pulso, or from scratch in its signature settings with the Twilio scheme. Twilio signs every request it sends with it.
In the Console’s Usage Triggers, under Billing and Usage > Usage and Spend, create a trigger that calls the source’s Endpoint URL,
https://hooks.pulso.run/webhooks/<id>/<token>, byPOST. Add one for each category and threshold you want to hear about.With the Twilio CLI
twilio api:core:usage:triggers:create --usage-category totalprice --trigger-by price --trigger-value 50 --recurring daily --callback-url https://hooks.pulso.run/webhooks/<id>/<token>In the Console’s Debugger, set the same URL as its webhook to get each error and warning it logs.
What arrives#
Both send form fields, which become columns as they are named. A usage trigger sends:
| Column | Example |
|---|---|
UsageTriggerSid |
UT33c6aeeba34e48f38d6899ea5b765ad4 |
UsageCategory |
totalprice |
TriggerBy |
price, count or usage |
TriggerValue |
50 |
CurrentValue |
52.31 |
Recurring |
daily, monthly, yearly, alltime, or empty for a trigger that fires once |
DateFired |
when it fired |
AccountSid, UsageRecordUri, IdempotencyToken |
the account, the usage record to read and the delivery’s id |
The Debugger sends Sid, AccountSid, Timestamp, Level (ERROR or WARNING), PayloadType and Payload, a JSON string with the error_code, the resource_sid it’s about and, for a webhook of yours that failed, the request and response.
Monitors to build#
Usage over its trigger#
- Filters:
UsageTriggerSidstarts withUT, which only usage triggers send. - Uniq by:
UsageTriggerSidandDateFired, one signal each time a trigger fires. - Playbook: a question, “Expected?”. If it is, a task to raise the trigger; if not, a task to find where the usage comes from, with what to check for SMS pumping.
Twilio errors#
- Filters:
LevelequalsERROR. AddPayloadcontains30007, or another error code, to keep the ones you act on. - Uniq by:
Sid, one signal per error. - Playbook: a task to look into the error, with its
Payload.
Limits#
- Signed with your Auth Token. Twilio signs requests with the account’s Auth Token, so the source keeps it, encrypted. After rotating it in Twilio, paste the new one: the old one keeps verifying until you forget it.
- The Payload stays a string. Monitors read the Debugger’s
Payloadas text, so filter on it with contains rather than on its fields. - Once per period. A recurring trigger fires at most once per day, month or year, in GMT, and Twilio checks usage about once a minute, so a spike shows up a few minutes late.
Sources: Twilio’s Usage triggers, Webhooks security and Debugging events webhook.
Add Twilio to Pulso: a webhook source, 2 monitors with their playbooks and a report, then these steps with the source's URL.
Add to Pulso