Introduction
In this tutorial, let's take a look at how we can execute a python script whenever we send a text message to a specific number using WayScript. Additionally, we'll look at how we can pass variables to a python script using this text message to create custom responses. Let's get started!
Text Message Trigger
The WayScript text message trigger allows us to execute a script whenever a text message is sent to a certain number, containing an execution command for the script you're trying to execute. For example, the text may look something like this:
Building this in WayScript, we pull a time trigger into our workflow and turn it on:
The first time you use this module, you will have to connect your phone number for verification. After that, we can configure the outputs to receive from the test message. These are the values following the execution command in your message.
Here we're creating a variable called message, which will get assigned the value provided in the text message.
Executing a Python Script
Since we want this text message to execute a python script, let's pull a python module as the next step in the workflow.
By placing this under an activated text message trigger, this python script will execute any time a message is received. However, to provide a customized response, let's do something with the input provided by the user's message.
We could write some python code like this:
message = variables['message']
string_message = str(message)
response_string = 'Hello ' + string_message
variables['response_string'] = response_string
While we're not doing much here, we're taking the input, processing it, and creating a new variable that we can pass to another module. We can "export" this new variable out of python and back to Wayscript using the variables dictionary. There's limitless possibilities at this step.
Passing Back a Response
Now that we've created the response in the python module. Let's pass it back as a text message to the user.
We can write the response that we want into the body of the message. But in this example, let's just use that variable we created by dragging it in.
This will return that python response directly back to the user.
Questions, Feedback?
As always, if you have any questions please reach out to us on our Discord and we would be happy to help. If you want to view this completed script, you can find it here.
Meet and connect with Derrick from WayScript. The star of these scripts and creator of these amazing tutorials:
Top comments (0)