SMS autoresponders are effective tools for quickly disseminating information.
Let’s say you lease apartments. Apartment listings can be sent to interested parties automatically. Alternatively, you can use automated SMS to invite new customers to sign up for a mailing list. A guest can speak with a virtual agent to arrange for cleaning, request additional supplies, and make other routine requests; entire interactions can be completely automated.
You can communicate with end users with little effort if you take the upfront steps to incorporate an autoresponder into your program. Additional advantages include time savings, improved client satisfaction, and increased customer involvement.
This article will teach you how to use ClickSend and Python to create an SMS autoresponder for an event location.
An SMS autoresponder: what is it?
A mobile number that has an automated rule set up to execute whenever it receives messages containing specific keywords is known as an SMS autoresponder.
Autoresponders are capable of much more than just providing information, though.
Autoresponders can be used to subscribe clients to mailing lists and/or SMS automations, as well as to gather user data for customer service. or to develop a customer service virtual assistant.
Configuring Python SMS autoresponders
In this example, the autoresponder will react to SMS inquiries about a fictitious event location. Using the words “Friday,” “Saturday,” or “Sunday,” visitors will be able to submit messages and get details on the event that is planned for that day.
An answer to a query like “Hey, what’s happening on Sunday?” would look something like this: “Local pop star concert.” Ariana Grandeur is the performer. begins at 9 p.m. Admission costs $15.
Note: ClickSend’s SDK is explained in this tutorial. If you want a no-code solution, ClickSend also provides an easy-to-use online user interface with comparable functionalities.
Requirements
What you’ll need to follow this guide is as follows:
Python 3.4+
An installer for the ClickSend account Pip package
An exclusive ClickSend phone number. You’ll need to buy one if you don’t already have one (see how do I purchase a dedicated number?)
Get the Python SDK installed.
Installing the official SDK package is required in order to import our API into your project and use it from Python. Visit our Github repository to locate our official Python SDK.
Use the following command to install:
Your first rule of automation
You must put up certain automation rules before you can establish the autoresponder. Three rules will be submitted to the ClickSend API in this tutorial, one for each day that an event will occur.
Create a new file called autoresponder.py and open it in an editor to submit an automation rule to ClickSend.
Then import all required packages. ClickSend’s SDK, clicksend_client, and ast, which can convert a string to a dictionary among other things, are required:
Enter your authorization information here:
Replace API_KEY with your API key and USERNAME with your username. The ClickSend dashboard has the API key:
Now is the time to draft your first SMS rule. Initialize an API instance first:
Make a rule object:
The Thursday automation’s instructions are contained in this. It will automatically reply to messages that contain the phrase “Thursday” because message_search_type is set to 2 and message_search_term is set to Thursday. You can consult the official documents for additional details on these characteristics.
Unfortunately, you cannot add the response body—the text that the autoresponder should send back to the user—to the object using SDK methods because the function lacks an argument for it.
However, there is a field for this parameter in the API. The API will add a body field to the automation if you send it a JSON message, allowing you to manually add the answer content.
To accomplish that, turn your produced object into a dictionary and manually add the body property:
Send ClickSend this automation:
The following response ought to appear once the script has run:
Creating autoresponders automatically
It may take some time to manually add events by modifying rules. It is preferable to automate this process using Python so that the venue script can automatically create the rules based on event descriptions. To set up the SMS automations for the week, you would actually run this script at the beginning of each week.
Delete everything in your file up until the API instance is initialized before proceeding with this section.
You must first write a function that will simulate an API response. It will obtain a dictionary of the week’s events. This would be an API call to your event management system in the real world. Make use of the code below:
Next, write a helper function that, given a day and a description, will produce a rule:
Upload the rules to ClickSend after iterating over the dictionary of events.
If a rule already exists, you should change it rather than make a new one. This prevents you from sending the user several messages by ensuring that you only have one rule every day.Instead of posting a new rule, you can write a helper function that determines whether an existing one exists and updates it if it does.
The following is the code for such a function:
This code retrieves all of the rules from ClickSend and then transforms the string answer into a proper Python dictionary using ast.literal_eval(). A rule retrieves the ID and updates it if its trigger phrase matches the one you’re submitting. You’re presuming that in situations when more than one item has the same trigger phrase, the function doesn’t need to be defined.
It will post the rule if the specified trigger phrase has no rules.
Calling these functions is all that is required:
Note: To keep things simple, this example calls the lookup on each call; to cut down on lookups, you could wish to shift the call.
Automated testing
All of your active automations are shown in Inbound SMS. Send a brief SMS to yourself using the ClickSend dashboard if you wish to test a certain automation:
Your message history should display the messages:
As you can see, any query utilizing weekend day names and details about the event planned for that day is correctly answered by the automation.
Give it a try.
Using Python to build components or software? In addition to adding autoresponders, you may manage your account, add or amend contact lists, send messages by MMS, voice, fax, and more by calling our other endpoints. View our documentation for the Python API here.