I then worked out a second iteration using Alexa and IFTTT to write a file to a dropbox folder. I have an Automator action watching this folder that runs a shell command to deploy the code and then deletes the file.
This post covers the details on setting up this process.
Prerequisites
- IFTTT account
- Dropbox account and registered with IFTTT
- Amazon Alexa and Dropbox accounts registered with IFTTT
For this documentation I will be using an Alexa skill project called College from an Alexa Developer repo that is used for one of their instructional broadcasts on https://www.twitch.tv/amazonalexa. During one of these episodes is where I had the idea of Alexa triggering ASK CLI deploy. This process will work with any project, just replace the path to point to a different project.
1. Log into IFTTT and navigate to "My Applets" then click on "New Applet".
1. Log into IFTTT and navigate to "My Applets" then click on "New Applet".
2. This will begin the New Applet walkthrough. Click on the blue +this.
3. This will ask you to select your triggering service. In the choose a service search box type in Alexa and then click on the Amazon Alexa tile.
4. In the Choose Trigger select "Say a specific phrase".
5. In this prompt you will type in the voice command that you want to say to Alexa to trigger this process. IFTTT does need the invocation to be "Alexa trigger " + your phrase. So in this example if "deploy college coach" is the phrase, the full voice command you say to Alexa would be "Alexa trigger deploy college coach". Press Create Trigger when you are done with your phrase.
6. The next step in the process is to choose what service is triggered when the Alexa phrase is triggered. Click on +that to select the service.
7. This will ask you to choose the action service. In search box type dropbox and then click on the Dropbox tile
8. We will want IFTTT to create a text file in our Dropbox so select "Create a text file"
9. In this Create a text file screen is where all the magic really happens. Here is where we will specify the shell script commands and the dropbox folder that the resulting text file will be created in. The two key components on this screen are the Content and Dropbox Folder Path
FileName: The default is "Amazon Alexa" + trigger date and time. I did not modify this at all
Content: This is where you add the shell commands that you want to execute. Set the Path so the shell command has access to the ask command, navigate to the path of the project(include your specific path) that you want to deploy, and then the ask deploy command.
PATH=/usr/local/bin:$PATH<br>
Dropbox folder path:I changed this to "AlexaAutomation" and manually created the folder in Dropbox. Make note of what you set this to, we will set up folder monitoring.
Create Action when done.
10. Review your action and set up notification if you wish, then click finish. Once you create this, it may take a few minutes for IFTTT to get it registered and available for your Alexa device.
11. The second part of this implementation is to set up an Automator service to watch for files added to the Dropbox folder that you specified in your IFTTT applet.
Open Automator on your Mac, create a new file, and then choose Folder Action as the type.
12. In the "Folder Action receives files and folders added to" click in the selector, choose Other, and then point to the Dropbox folder that you specified in your IFTTT applet. (if the folder does not yet exist, go ahead and create it).
13. With the "actions" tab and "Library" selected in the upper left of Automator type "Run Shell Script" in the search folder, then drag the Run Shell Script icon to the main workflow window.
Set the following items:
Shell: /bin/bash
Pass Input: as arguments
Include the following code to the shell content window
for f in "$@"
3. This will ask you to select your triggering service. In the choose a service search box type in Alexa and then click on the Amazon Alexa tile.
4. In the Choose Trigger select "Say a specific phrase".
5. In this prompt you will type in the voice command that you want to say to Alexa to trigger this process. IFTTT does need the invocation to be "Alexa trigger " + your phrase. So in this example if "deploy college coach" is the phrase, the full voice command you say to Alexa would be "Alexa trigger deploy college coach". Press Create Trigger when you are done with your phrase.
6. The next step in the process is to choose what service is triggered when the Alexa phrase is triggered. Click on +that to select the service.
7. This will ask you to choose the action service. In search box type dropbox and then click on the Dropbox tile
8. We will want IFTTT to create a text file in our Dropbox so select "Create a text file"
9. In this Create a text file screen is where all the magic really happens. Here is where we will specify the shell script commands and the dropbox folder that the resulting text file will be created in. The two key components on this screen are the Content and Dropbox Folder Path
FileName: The default is "Amazon Alexa" + trigger date and time. I did not modify this at all
Content: This is where you add the shell commands that you want to execute. Set the Path so the shell command has access to the ask command, navigate to the path of the project(include your specific path) that you want to deploy, and then the ask deploy command.
PATH=/usr/local/bin:$PATH<br>
cd /Users/iScreem/Dropbox/Alexa/Dev/CollegeCoach<br>
ask deploy --target lambda
Dropbox folder path:I changed this to "AlexaAutomation" and manually created the folder in Dropbox. Make note of what you set this to, we will set up folder monitoring.
Create Action when done.
10. Review your action and set up notification if you wish, then click finish. Once you create this, it may take a few minutes for IFTTT to get it registered and available for your Alexa device.
11. The second part of this implementation is to set up an Automator service to watch for files added to the Dropbox folder that you specified in your IFTTT applet.
Open Automator on your Mac, create a new file, and then choose Folder Action as the type.
12. In the "Folder Action receives files and folders added to" click in the selector, choose Other, and then point to the Dropbox folder that you specified in your IFTTT applet. (if the folder does not yet exist, go ahead and create it).
13. With the "actions" tab and "Library" selected in the upper left of Automator type "Run Shell Script" in the search folder, then drag the Run Shell Script icon to the main workflow window.
Set the following items:
Shell: /bin/bash
Pass Input: as arguments
Include the following code to the shell content window
for f in "$@"
do
bash "$f"
rm "$f"
done
This will execute the contents of the text file, then delete the file when done.
14. (Optional) search for "Display Notification" in the Actions and Library. Drag into the workflow and set the Notification to what you would like.
15. My completed Folder Action looks like:
16. Save the Automator action and you should be all done
This one Automator action should look for and execute any IFTTT applets that write to that folder. You could create addition IFTTT applets for different projects, or full deploys vs lambda deploys. Just configure new IFTTT trigger phrases such as "Full Deploy College Coach" and include the full deploy code in the text file.
Then you should be able to say "Alexa trigger deploy college coach" and it will create the file in dropbox, Automator will see and execute it deploying the code, then delete the file and send a notification.












No comments:
Post a Comment