How to: Send a text message with Twilio

Webhooks all do essentially the same thing: send data to another server to trigger some action.

Send data to external services/endpoints. You can send Leanplum data to an external endpoint using a webhook. The webhook can be triggered on an event in Leanplum, and contain contextual information from parameters for that event. Even scheduled webhooks can contain the user's userId and any other information about that user available in Leanplum.

Trigger a third-party API. You can send an API call to a third-party API or service using a webhook. This is often used to send an email or a text message using a third-party messaging service. You can pass data from Leanplum into the webhook call using Jinja, a templating language we use to insert dynamic values for each user.

Send a text message with Twilio

For more on how to send a text message with a webhook call to Twilio, see Send an SMS with Twilio.

Set a user attribute using the Leanplum API. Rather than update and resubmit your app to make a user attribute change via our SDK, you can set up a webhook to do this automatically.

Let's say you have a rewards membership program with three statuses: silver, gold, and platinum. You could create an event called "updateStatus" with an event attribute "newStatus". This event would be tracked any time a user upgraded or downgraded their status, and pass along their new status level in the "newStatus" attribute.

Leanplum.track("updateStatus", withParameters: ["newStatus": "Gold"])

Using a webhook, we can then call the Leanplum API method setUserAttributes to set "currentMemberStatus" to the new value every time this event is triggered by a user.

  1. Set the webhook URL to the Leanplum setUserAttributes endpoint, including your app id and production key from Keys & Settings. Be sure to use {{User ID}} and {{parameter['newStatus']}} to dynamically insert those values into the call for this user.
  1. Set the delivery to Triggered, and select User triggers event. Then enter the event name ("updateStatus"). Note: You must trigger the webhook off the event for its event attribute to be available in step 1 above.

Now, when the user upgrades to Gold status, the user attribute "currentMemberStatus" will be set to "Gold". This is visible in the Users dashboard.


Did this page help you?