Achieving 2 way SMS with Marketo will help you stay in compliance with SMS regulations by appropriately responding to customer requests to be unsubscribed or requests seeking help. As you have probably seen in the SMS you have received from companies, this is done using keywords of “STOP” and “HELP” to automatically send appropriate responses.
This post will walk you through how to build an inbound SMS responder using the Zapier automation tool and the Telnyx app that will respond to these keywords and support the outbound SMS that you send from Marketo.
On a separate note, have you checked out the Marketo API Crash Course yet? If you want hands-on video walkthroughs of how to get set up with the Marketo API and see real-life marketing operations use cases for the API then check out the course using the button below 🙂
If you are looking for an introduction to the Telnyx CPaas platform and why they should be your SMS provider take a look at the Marketo SMS Marketing with Telnyxpost where I explain the pricing and features of Telnyx SMS. Also, if you want a sneak peek at the cool things you can do once you have set up 2 way SMS in Marketo then check out theMarketo SMS Integration: Webinar Reminders post.
Before starting with the steps below make sure you have followed the Telnyx SMS Quickstart Portal Setup Guide to do the prerequisites below.
N.B. Make sure to sign up using this referral link to get a sweet, sweet $20 in free credit.
Create a free Telnyx portal account
Buy an SMS capable phone number
Create a messaging profile
Associate your SMS number with this messaging profile
Once you have sent outbound SMS from within Marketo you can then use the Zapier automation tool to define the logic to automatically send follow-up SMS in response to inbound queries.
1. Inbound SMS to Messaging Profile Trigger
Follow the steps below when creating your new Zap to set up a trigger for inbound SMS to one of your Telnyx messaging profiles.
Select the “Telnyx” app
Select the “Receive a Message” event
Click “Continue”
Click on the “Choose an account” dropdown
Select “Connect a new account”
Enter your “v2 API Key” and “v2 profile id” in the window that pops up
Now any inbound SMS to any of the numbers associated with this messaging profile will trigger this Zap to run.
2. Parse Inbound SMS and Choose Outbound Response
In order to parse the inbound SMS for certain keywords and determine the corresponding response, the Python code below will be used in the “Code by Zapier” action.
It is not necessary to specify a message for the “STOP” response in the Python code because Telnyx automatically has an auto-response for opt-out keywords including “STOP”. The SMS below is sent to the person if their SMS includes the word “STOP” and Telnyx protects this person from receiving any more SMS from the number that sent the SMS.
“You have successfully been unsubscribed, you will not receive any more messages from this number. Reply START to re-subscribe.”
Telnyx “STOP” auto-response
If someone wants to re-subscribe to SMS then the auto-response below will be sent when they reply with “START”.
“You have successfully been re-subscribed to this number. Reply STOP to unsubscribe. Msg&Data Rates May Apply.
Telnyx “START” auto response
message='NA'
keyword='NA'
subscription = True
if 'stop' in input['inbound_text'].lower():
keyword = 'stop'
subscription = False
elif 'start' in input['inbound_text'].lower():
keyword = 'start'
elif 'help' in input['inbound_text'].lower():
message = 'This is Telnyx Marketing. Reply STOP to unsubscribe. Msg&data rates may apply. https://support.telnyx.com.'
keyword = 'help'
else:
message = 'Thanks for reaching out. If you require assistance please visit https://support.telnyx.com.'
return{'outbound_message':message, 'keyword':keyword, 'subscription':subscription}
3. Send Response using Telnyx SMS API
Selecting the “Code by Zapier” action will allow you to use Python code to send the outbound response from Step 2 to the number that texted into the messaging profile. The Telnyx app does have a “Send SMS” action (see Step 5 below), however, the “Code by Zapier” action was used so that conditional logic could be added to ensure that an SMS will not send when the keyword is “stop” or “start” since Telnyx automatically responds to these keywords (see Step 2 above).
import requests
import json
if 'stop' not in input['keyword'] and 'start' not in input['keyword']:
url = "https://api.telnyx.com/v2/messages"
payload = json.dumps({'from': input['from_number'] ,'to': input['to_number'],'text': input['message']})
headers = {
'Authorization': 'Bearer '+input['api_key'],
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return {'response':response.text}
return {'response':'skipped send'}
If you want to get alerted whenever there is an inbound SMS to a number on your messaging profile you can use the “Email by Zapier” action to forward details of the SMS to your email inbox. You can also include the response sent in reply to the inbound SMS (if a response is sent from Step 3) and a link to the history of the Zap for easy follow-up and debugging if necessary.
5. SMS Alert for Inbound SMS
Additionally, if you also want SMS alerts for any inbound SMS then you can use the “Send SMS” action from the Telnyx app using the account you created in Step 1. Unlike, the email alert I would not recommend including the response from Step 3 since the response is very long. There is also no need to include the “To Phone Number” since the number you will receive the alert from will be the same number that the inbound SMS was sent to.
Although using Zapier on mobile will not be the most friendly user experience, you can also include the link to the Zap’s history for quick access.
Setting Subscription after “STOP” or “START” Response
After the appropriate SMS has been sent to the customer it may then be necessary to unsubscribe them from or resubscribe them to SMS notifications. As mentioned previously, if someone replies with “STOP” then Telnyx will automatically prevent this person from receiving further SMS, and conversely, when someone replies “START” it will re-enable SMS to this person.
While this is the case, you should still have a field in Marketo e.g. “SMS Subscription – Webinar”, for a person’s SMS subscription and turn this to
False for the “stop” keyword so that you are not unnecessarily sending SMS from Marketo that will be blocked by Telnyx
True for the “start” keyword so Marketo knows it can start sending outbound SMS to this person again
6. Only Continue if Keyword is Stop or Start
This is a simple filter that will only allow the Zap to continue if the keyword variable from Step 2 contains the word “stop” or “start”.
7. Get Marketo Access Token
A “Code by Zapier” action is used with the Python code below in order to get the access token necessary to do the lookup in Step 8. If you need help finding your Marketo REST API authentication credentials then look at the authentication section in the Marketo REST API docs.
The “Create or Update Lead in Marketo” action used in Step 9. can only use the person’s email address to do the lookup. Consequently, that means we need to match the phone number of the person who replied to their email address in Marketo.
The Marketo REST API offers the option to query leads using fields and their values as filters. Note that it is necessary to URL encode the lookup phone number for the request to go through successfully. Additionally, in the case that multiple leads share the same phone number the findall function is used to get the returned information for all matching leads and by default the email of the first matching lead will be returned by this code.
One thing to note though is that fields with the type of “Phone” cannot be used in the lookup request. Therefore, a workaround needs to be implemented to transfer the value from the phone type field to a string type field that can then be used in the lookup request.
This is achieved using a Marketo smart campaign that triggers anytime the phone field (“Form – Marketing Phone” in this case) changes and then transfers the value of this phone field to a string field (“Form – Marketing Phone Lookup”) using the lead token. This string field is then the one that should be referenced in the lookup request above.
N.B. Notice how the default “Phone” field, which maps to the “Phone” field on the lead and contact in Salesforce, is not being used here. The reason for creating a separate phone field is to ensure that only marketing will have access to this phone number and that sales members cannot reach out to leads using this phone.
9. Create or Update Lead in Marketo
The email address obtained from Step 8. can now be used in the “Create or Update Lead in Marketo” action to identify the person and change their SMS subscription field e.g. “SMS Subscription – Webinar”, to true/false using the subscription value returned from Step 2.
Using 2 Way SMS with Marketo
Now that your 2 way SMS mechanism for Marketo is firing on all cylinders take a look at how you can use SMS communications for webinar reminders in the Marketo SMS Integration: Webinar Reminders post.
I encourage you to make the zap above your own. The exact same logic used in Step 2 above can be used to build auto-responders for any marketing campaign. For example:
If SMS contains “Yes” then send X
If SMS contains “No” then send Y
Else send Z
So go wild!
About The Author — Tyron Pretorius
Greetings fellow MO Pros! As a previous mechanical engineer turned marketing operations lead, I now fancy myself as a full-stack marketer capable of designing websites, writing SEO-optimized content, and doing all the tracking and automation on the backend.
That being said my bread and butter is marketing operations and I love to get down and dirty with the Marketo API, Python, Zapier, and Google Scripts.
Created with the assistance of DALL·E Introduction and Background In 2018, Edward Unthank introduced the four pillars of marketing operations, setting the stage for the management of effective marketing technology (Martech) functions. These pillars have since been the bedrock for many successful careers in marketing operations. My journey to redefine
Introduction When it comes to account-based marketing (ABM), your marketing team might have invested in intent data, built tailored content, and spent time targeting accounts. But is the juice worth the squeeze? You could say marketing operations teams are there in part to squeeze every last marketing dollar in order
Introduction: Blending Human and Technical Perspectives in Martech Caption: Future gardens of martech will blend human and AI perspectives As a co-host of the Humans of Martech podcast, I’ve had the privilege of interviewing some of the brightest minds in marketing technology. This unique experience has provided a blend of