Skip to contentSkip to navigationSkip to topbar
Rate this Page:

Test TwiML Bins using twilio-cli


(information)

Info

The Webhook Plugin is still in an experimental stage and is part of Twilio Labs(link takes you to an external page). If you find any issues, please open an issue on our GitHub repository(link takes you to an external page).

With the Twilio Labs Webhook Plugin(link takes you to an external page) you can simulate webhook events. These will not result in actual HTTP requests made from Twilio but instead are HTTP requests made from your machine that pass mock data that has a similar shape to the data Twilio would pass in a request.


Setup

setup page anchor

If you don't have twilio-cli installed yet, make sure to install it first and log in using twilio login.

After setting up twilio-cli you'll need to install the Webhook Plugin:


_10
twilio plugins:install @twilio-labs/plugin-webhook


Once you have the Webhook Plugin installed, you can use the twilio webhook:invoke command to simulate a webhook event to the URL that you pass:


_10
twilio webhook:invoke <your-twiml-bin-url>

An example with a TwiML Bin would look like this:


_10
twilio webhook:invoke https://handler.twilio.com/twiml/EHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Because TwiML Bins validate the X-Twilio-Signature header of a request, you'll have to either have the valid Auth Token for your account stored as an environment variable with the name TWILIO_AUTH_TOKEN, or pass in the Auth Token using the --auth-token argument. This Auth Token has to match the Account SID of your CLI profile & TwiML Bin. Otherwise, you can change the Account SID by using the --account-sid flag.

Once you execute your command, you'll see the TwiML response from your TwiML Bin. For example:


_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Message>Ahoy</Message>
_10
</Response>

If you also want to check the HTTP response headers, you can use the -i flag.


Simulating different events

simulating-different-events page anchor

By default, the twilio webhook:invoke command will simulate an SMS event. You can change the type by using the --type flag.

For example the following will simulate a phone call request instead:


_10
twilio webhook:invoke <your-url> --type=voice

If you want to modify some of the mock values that are being passed, for example to change the body of an incoming message you can use the -d flag:


_10
twilio webhook:invoke <your-url> --type=sms -d Body="Ahoy there!"

If you want to learn more about the options you can pass into the Webhook Plugin, you can run twilio webhook:invoke --help or visit the GitHub repository(link takes you to an external page).


Rate this Page: