Alexa Go Local

In the last few days, I’ve been exploring the world of Alexa Development. One of the challenges I’ve found, is that it wasn’t immediately obvious how to run and test your skill locally.

In this post, I’ll show you how to spin up a skill on localhost, and test it from the alexa developer portal. Ah! you probably already guessed from the title, but we’ll be using Golang today!

First, you need to setup your local skill server, think of it as a Lambda function you’ll host on your machine, therefore much easier to test. Luckily there is a great go pkg out there already for this.

Let’s create our project and call it Greeter, make sure you replace github.com/danielcondemarin with your own namespace!

1
2
3
cd $GOPATH/src/github.com/danielcondemarin/
mkdir greeter && cd "$_"
touch main.go

Now go get the skill server pkg:

1
go get github.com/mikeflynn/go-alexa/skillserver

In your favourite editor, change main.go to:

Now head onto the developer portal and create the skill:

Create Skill Step 1

Create Skill Step 2

After creating the skill, take a step back, copy the Skill ID on the main dashboard and set AppID in main.go.

You can now build the go skill server, and run it. By default will be hosted on http://localhost:3000

1
2
go build *.go
./main

Next, set an invocation name, just greeter will do. We will also need an intent and intent slot for the person name we want to greet!

Skill Intent

Notice the name’s slotType is already provided by Amazon, AMAZON.GB_FIRST_NAME. You will also want to set the slot required to fulfill the intent, to do that just click on the slot and enable the first toggle. Provide a prompt for the user to fill the slot too.

Next up, the Skill Endpoint, but before we configure that, go and download ngrok. If you don’t know what ngrok is, it’s basically a way for you to expose on the public internet a local port or service in your machine.

Run ngrok and set it to forward to port 3000 over http:

1
./ngrok http 3000

Copy the HTTPS URL, not HTTP! as Amazon requires a secure connection, go to the developer portal and on the Endpoint section select an HTTPS endpoint and paste the ngrok URL plus the path /echo/greeter (Mine was https://aa60ae80.ngrok.io/echo/greeter). Make sure you select “My development endpoint is a subdomain of a domain that has a wildcard certificate …”.

Click Save Model, Build Model, and we are good to test!

Here is a screenshot with a few utterances I tried:

utterances

That’s the end of the blog post, hope you’ve enjoyed it and feel free to comment below if you have any questions!