Run a Python Script with a Google Assistant Voice Command
Tags: python, tutorial, showdev, discuss
Published: 2019-09-09 21:36:21

## The "WayScript Trigger" Google Assistant Action

In this tutorial, you will learn how to use WayScript to run your Python script in the cloud using a Google Assistant voice command. (Check out the [Google Assistant Bot template](https://wayscript.com/library/Google_Assistant_Bot) to try it out!) 

This is done using the [WayScript Trigger action](https://assistant.google.com/u/0/services/a/uid/000000dfb9940d69?hl=en-US&source=blog), which you will first need to enable on your Google account. 

After enabling the action, you will then need to link it to your WayScript account using the Google Assistant app.

## The Google Assistant Action

The next step is to build a WayScript program with a Google Assistant Trigger. To do so, first go to your WayScript dashboard and select "Create a new Script". 

Give your program a name, like "Run Python with Google Assistant".

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/0manudnxuwq63ftdptkl.png)

Once your program is created, you'll start by adding a [Google Assistant Trigger](https://docs.wayscript.com/library/triggers/google-assistant-trigger). 

Click the "+" icon next to "Add Trigger(s)" and select the Google Assistant Trigger.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/zyfa6k7ec82fcsxxabgj.png)

You should now have the Google Assistant Trigger in the "Triggers" section of your program.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/w98o72adml2q0f8i2n1k.png)

## Set up the Google Assistant Trigger

Now that you have added the trigger to your program, let's get it set up! Start by clicking on the trigger to open it in the settings panel. 

You should see something like this:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pbdubzny86b7sh9hbklx.png)

Set "Activate Trigger" to "On".

If you haven't yet linked your Google Assistant account, select "Add an Account..." from the "Select an Account" dropdown.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/u9c5a2bba2yqzjvg9z0x.png)

This will show a dialog with the option to "Enable Action and Link Account" on the Google Assistant site.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/my8dadn6mhrbhhq9bflz.png)

Now, notice that the trigger shows the text "Hey Google, ask WayScript Trigger to run 'Run Python with Google Assistant'." 

That's kind of a mouthful, so you'll set the "Program Alias" field to create a phrase that's easier to say and easier for your Google Assistant to understand. 

In this case, you'll simply set the Program Alias field to "Python". 

Now you have a much nicer phrase!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/l0k64f4ae4g4sbuzwk2a.png)

## Add a Python Script

With the Google Assistant Trigger in place, it's time to add a Python Script. Start by dragging the [Python module](https://docs.wayscript.com/library/modules/python) into your program.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/jpfv9iza828my1nkpo93.png)

Then, click on the Python module and paste your script into the code box.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/q7lu26pabxc4mrszhphk.png)

## That's it! You're done!

Run your Python script from any of your Google Assistant-enabled devices by saying *"Hey Google, ask WayScript Trigger to run 'Python'*." 

Of course, you don't have to stop at Python. You can run any WayScript program - including an evergrowing list of modules - using the Google Assistant Trigger.