Tutorial: Execute Python Scripts Via Text Message
Tags: python, tutorial, beginners, automation
Published: 2020-05-11 14:26:52

---
title: "Tutorial: Execute Python Scripts Via Text Message"
canonical_url: https://wayscript.com/learn/execute-python-scripts-via-text-message
---
##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](https://wayscript.com/). 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:

![text example](https://cdn.wayscript.com/blog_img/89/1.png)

Building this in WayScript, we pull a time trigger into our workflow and turn it on:

![Time Trigger](https://cdn.wayscript.com/blog_img/89/2.png)

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.

![Output variables](https://cdn.wayscript.com/blog_img/89/3.png)

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.

![python module](https://cdn.wayscript.com/blog_img/89/4.png)

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:

```python
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.

![Text message](https://cdn.wayscript.com/blog_img/89/5.png)

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.

![response](https://cdn.wayscript.com/blog_img/89/6.png)

This will return that python response directly back to the user.

![response](https://cdn.wayscript.com/blog_img/89/7.png)

##Questions, Feedback?
As always, if you have any questions please reach out to us on our [Discord](https://discord.gg/nchf9E9) and we would be happy to help. If you want to view this completed script, you can find it [here](https://wayscript.com/user/derricks/hv5ZoHOi).

Meet and connect with Derrick from WayScript. The star of these scripts and creator of these amazing tutorials: {% user derricksherrill %}