Tell Alexa to trigger your deployment
Tags: actionshackathon, iot, alexa, github
Published: 2020-08-19 03:10:27

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon, please fill out all sections.)

{% twitter 1295919875760762881 %}

### My Workflow
[Note]: # (Make sure to include the name of your GitHub Action and share where it's being used!)
The "on voice" workflow uses the workflow_dispatch event to trigger the github action via the github rest api. This action is just a proof of concept for allowing you to interact with your repo by voice, and is not used anywhere except the repo I've created for this actionsHackathon submissions.


### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)
Interesting IoT


### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)
[onvoice.yml](https://github.com/rdlucas2/actionsHackathonSubmissions/blob/master/.github/workflows/onvoice.yml)


### Additional Resources / Info

The code used in the action is really nothing special. I've left it as the "default" action template but just changed the event trigger to "workflow_dispatch". This allows me to call the rest api targeted at the "onvoice.yml" file, which in turn would kick off any deployment defined within. The idea here is that you could tell alexa to trigger {your project name} deployment, and have it kickoff this process.

To set this up, you'll need an [IFTTT](https://ifttt.com) account, and add the Alexa service.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h04ivxx63zg4ujoy93g0.png)


Once you connect the Alexa service, setup a new trigger for "say a specific phrase".  
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uxmhopn4afftlj1fk0m4.png)

Fill out the form with something like "my deployment" - when you interact with alexa you'll say "Alexa, trigger my deployment"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uqxyb97s6a99i5wywp5y.png)

Then, for the action - search for "webhook" and set the action as "make a web request"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6yzevosx4q2qp8y48g3o.png)

This is where things got a little funky. I could not get this web request action to properly authenticate to the github rest api. I tried doing basic auth in the url with https://user:pat@api.github.com... which works with curl but not via ifttt. Unfortunately the ifttt interface doesn't give you a lot of options for customizing your http request, so I ended up setting up an azure function to bypass this problem. My webhook instead calls the function app URL, which in turn calls the workflow dispatch. The curl for the call looks like this:

```
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/{USER}/{REPOSITORY}/actions/workflows/{WORKFLOW_ID_OR_YML_FILE_NAME}/dispatches \
  -d '{"ref":"{BRANCH_NAME}"}' \
  -u {USER}:{PAT}
```
Anything surrounded with curly braces {} would be specific to your account/repository. Learn how to make a Personal Access Token (PAT) here: [Create a PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). You can read up on the workflow_dispatch event here: [Workflow Dispatch Trigger Event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) and the github rest api for calling the workflow dispatch event here: [Workflow Dispatch Rest Api Call](https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event).


[Note]: # (Be sure to link to any open source projects that are using your workflow!)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on September 12th (11:59 PM PDT) and winners will be announced on September 23!)