Building an Alexa-Based GitHub Follower Counterby@mlabouardy
927 reads

Building an Alexa-Based GitHub Follower Counter

Read on Terminal Reader

Too Long; Didn't Read


Company Mentioned

Mention Thumbnail
featured image - Building an Alexa-Based GitHub Follower Counter
Mohamed Labouardy HackerNoon profile picture

@mlabouardy

Mohamed Labouardy
react to story with heart

image

This post is part of “Alexa” series. I will walk you through how to build an Amazon Alexa Skill with Node.JS and Lambda to get numbers of followers & repositories in GitHub in real-time.

Note: all the code is available in my GitHub.

image

Amazon Echo will captures voice commands and send them to the Alexa Skill to convert them into structured text commands. A recognized command is sent to an AWS Lambda function that will call GitHub API to get response.

To get started, sign up to Amazon Developer Console, and create a new Alexa Skill:

image

The invocation name is what user will say to trigger the skill. In our case it will be “github“.

Click on “Next” to bring up the Interaction Model page, use the intent schema below:

Intents will map user’s voice command to services that our Alexa skill can address. For instance, here I defined an intent called GetGithubFollowerCount, which will line up with a portion of code in my Lambda funtion that I leverage in a bit.

The programming languages are defined as a Custom Slot Type, with the following possible values:

GoJavaPythonCC++JavascriptHTMLScalaOcamlNodeJSRubyPHPCSSC#PerlShellObjective C

Now our intents are defined, we need to link them to a human request that will trigger this linkage. To do this multiple sentences (utterances) are listed to make the interaction as natural as possible.

GetGithubFollowerCount how many followers do I haveGetGithubFollowerCount current followersGetGithubFollowerCount number of followers

GetGithubRepositoryCount how many repositories do I haveGetGithubRepositoryCount number of repositoriesGetGithubRepositoryCount current repositories

GetGithubRepositoryCountByLanguage how many {Language} repositoriesGetGithubRepositoryCountByLanguage number of {Language} repositoriesGetGithubRepositoryCountByLanguage current {Language} repositories

Result:

image

Click on “Next” and you will move onto a page that allows us to use an ARN (Amazon Resource Name) to link to AWS Lambda.

Before that, let’s create our lambda function, login to AWS Management Console, then navigate to Lambda Dashboard and create a new function from scratch:

image

Select Alexa Skills Kit as trigger:

image

I wrote the Lambda functions in Node.JS, although that code isn’t actually that interesting so I won’t go into it in much detail.

This function is fired when there is an incoming request from Alexa. The function will:

  • Process the request
  • Call GitHub API
  • Send the response back to Alexa

Create a zip file consisting of the function above and any dependencies (node_modules). Then, specify the .zip file name as your deployment package at the time you create the Lambda function. Don’t forget to set your GitHub Username as an environment variable:

image

Back in the Alexa Skill we need to link our Lambda function as our endpoint for the Alexa Skill:

image

That’s it, let’s test it out using a Service Simulation by clicking on “Next“.

GetFollowerCount Intent :

image

GetRepositoryCount Intent:

image

GetGithubRepositoryCountByLanguage Intent:

image

You can see that the Lambda responds as expected !

Test it now with Amazon Echo, by saying “Alexa, ask GitHub for …” :

image

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa