Implement Twilio Messaging Using Webhooks

Implement Twilio Messaging Using Webhooks

By Sarah Leu Icon comments Tags: Development, Webhooks

Need to improve your marketing automation workflows? You can trigger 3rd party applications as an effect for any of your promotions by creating a webhook with Talon.One.

In the Talon.One Developer Tools, developers can create webhooks to other web applications and test the implementation within your account. A webhook is an HTTP callback which is triggered by an event; for instance, sending an SMS message when a new customer registers.

This article will show you how to use webhook feature by implementing Twilio, a communications platform for building SMS, voice and messaging applications, into a Talon.One ruleset.

Twilio-logo

1. Twilio Account Information

First you will need some information from your Twilio account before you implement the webhook in Talon.One.

You will need the following:

  • Account SID
  • Authorization Token
  • A Twilio phone number (the sent from number)
  • A verified recipient phone number on your Twilio account (necessary for testing).

The Twilio documentation gives a sample API command to send an SMS. This will tell us the information needed to create the Twilio webhook in Talon.One.

curl -X POST 'https://api.twilio.com/Accounts/account_SID/Messages.json' \  
--data-urlencode 'To=recipient#' \
--data-urlencode 'From=twilio#' \
--data-urlencode 'Body=Message Text' \
-u account_SID:authorization_token

You can execute this command to test that all your Twilio information is set up correctly.

2. Creating the Webhook in Talon.One

In the Talon.One Developer Tools, there is a setting to manage your webhooks. Here you can create your Twilio webhook.

Talon.One-webhooks-ui-screenshot

You will need to add a few key things for this webhook.

First, you need to add the parameters which are the recipient's phone number, the sender's phone number, and the text of the message. From the Twilio command, you can see that these three parameters are string types.

You can also see the parameters' Content-Type is data-urlencode so this information should be added as a Header like so Content-Type: application/x-www-form-urlencoded. The request for this webhook will be the exact same as the Twilio request, a POST to the Twilio messaging in your account.

You will also need to add an HTTP authentication header, but first you need to encode your Twilio Authorization Token. You should encode api:$your_authorization_token as base64 and add a Header like so Authorization: Basic your_encoded_auth_token. The last thing to add is the payload. A payload consists of the input parameters that the request contains and looks like this:

{
To: ${$To},  
From: ${$From},  
Body: ${$Body}  
}

3. Add Twilio messaging to a rule and test it!

Now that the Twilio Webhook is created, you want to implement it into a Campaign and test the functionality. You can head to the Campaign where you'd like to use it and go to the Rule Builder. Here you can create your rule, for instance when a new customer registers then send a SMS message saying "Welcome new customer!"

Once you have enabled the Campaign, you can head to the API Tester in the Developer Tools to create a command to test your new rule. For our example rule, you can create a new customer profile to test it. In the webhook logs, you will see the response to the request. If an error occurred you can see the response for debugging.

If your test succeeded, congrats! Now you can use this methodology to create other webhooks in Talon.One.

To learn more, check out our detailed guide or read integration guides or tutorials in our documentation. If you want a more in-depth look at Talon.One, we can schedule a live demo, just get in touch.

Subscribe to our newsletter

Get insights and inspiration for mastering promotion marketing.

Unsubscribe whenever you like.

There was an error subscribing to the newsletter. Please try again.

Thanks for subscribing to the Talon.One newsletter!

Related articles

Comments

Check out our Community Guidelines.