So you're using Twilio for Programmable SMS and you want a simple, fixed auto-responder message to be sent when any of your SMS recipients replies to your original message. How to do it?
Well, first you should know that Twilio will automatically handle replies that include words like
STOP, so you don't need to worry about that.
But for other replies, perhaps you want a simple message informing your recipient that it's best to contact you via email.
To do this, the key concept to understand is that Twilio wants to read your message text from some public URL that you configure. So you'll need a public folder on a website that you control, and you'll need to place your message in an XML file in that folder. Twilio will make HTTP requests to your site just like a regular web browser.
For example, here's a sample
<?xml version="1.0" encoding="UTF-8"?> <Response> <Sms> Thanks for replying. The best way to contact us is by email at [email protected]. </Sms> </Response>
Let's say that you have placed this file on a website at the following URL: http://www.yourdomain.com/public/Reply.xml. Now, you need to tell Twilio about this URL. You can do this in one of two ways: (1) Directly on an individual sender telephone number, or (2) Using a group of sender numbers under a "Messaging Copilot" service.
I'll describe the more flexible "Copilot" configuration, available from your Twilio account at https://www.twilio.com/console/sms/services.
Click on the big red button to add a new messaging service. You'll want to configure the "Request URL" setting to point to the URL for your
Reply.xml file. In this example: http://www.yourdomain.com/public/Reply.xml. Be sure to specify the correct protocol:
That's it. As long as Twilio can access the
Reply.xml file you should now see your auto-response message when replying to SMSs.
It's beyond the scope of this post, but it's also possible to dynamically emit response messages based on context, etc. To do this, you can include parameters and values in the configured URLs. Twilio sends this data to your site so that you can act upon it before responding.