As hackers, we like to think of ourselves as a logical bunch. But the truth is, we are as subject to fads as the general public. There was a time when the cool projects swapped green LEDs out for blue ones or added WiFi connectivity where nobody else had it. Now all the rage is to connect your project to a personal assistant. The problem is, this requires software. Software that lives on a publicly accessible network somewhere, and who wants to deal with that when you’re just playing with custom Alexa skills for the first time?

If you have a computer that faces the Internet, that’s fine. If you don’t, you can borrow one of Amazon’s, but then you need to understand their infrastructure which is a job all by itself. However, there is a very simple way to jump start an Alexa skill. I got one up and running in virtually no time using a website called Glitch. Glitch is a little bit of everything. It is a web hosting service, a programming IDE for Node.js, a code repository, and a few other things. The site is from the company that brought us Trello and helped to start Stack Overflow.

Glitch isn’t about making Alexa skills. It is about creating web applications and services easily. However, that’s about 90% of the work involved in making an Alexa skill. You’ll need an account on Glitch and an Amazon developer’s account. Both are free, at least for what we want to accomplish. Glitch has some templates for Google Home, as well. I have both but decided to focus on Alexa, for no particular reason.

Admittedly, my example skill isn’t performing a particularly difficult task, but it is a good starter and if you want to develop your own, it will give you a head start. Although I used a particular tool, there’s no reason you could not move from that tool to your own infrastructure later, if you had the need to do so. One nice thing about Glitch is that you can share code live and people can remix it. Think of a GitHub fork, but where you can try running my copy and your copy is instantly live, too. Turns out for the Alexa skills, having it live isn’t as useful as you’d like because you still have to tell Amazon about it. But it does mean there are example Alexa skills (including mine) that you can borrow to get yours started, just like I borrowed one to start mine.

Do You Need It?

The first question you might ask yourself is do you even need an Alexa skill? I recently got Alexa to control my 3D printers by using IFTTT with no software development at all required. However, if you really want to claim you work with a virtual assistant, you are going to have to write some code somewhere.

Of course, there’s the bigger philosophical question: do you need to do any of this? I’ll admit, I find it useful to have my 3D printers on voice control because I might be making adjustments with both hands and I don’t have to fumble with buttons to have the machine do a homing cycle, for example. I’m less sold that I need a virtual assistant to launch my drone. Then again, maybe that’s what you want to do and that’s up to you.

Getting Started

If you don’t already have one, you might as well go ahead and sign up for an Amazon developer’s account. Then head over to Glitch and register there, too. There are at least two templates for building an Alexa skill. There are a bare-bones one and a more involved one that retrieves weather forecasts. If you are looking at the page, it might not make much sense. Remember, the web server is meant to talk to Alexa, not people. In the top right corner is an icon with a pair of fish. If you click there, you can view the source or you can remix it.

I decided to remix the weather forecast service since I thought it was a better example. Then I cut away all the weather-related code (except some of the documentation) and wrote a simple Javascript function:

function get_fact() {
  var factArray = [
  'Hackers read Hackaday every day',
  'You know you are 3D printing too much when you tell someone you are extruding mustard on your hot dog',
  'The best microcontroller is the one already programmed to do what you want',
  'We can all agree. All software has bugs. All software can be made simpler. Therefore, all programs can be reduced to one line of code that does not work.',
  'I hate talking to flying robots. They just drone on.',
  'If you call your morning cup of coffee installing Java, you need a hobby',
  'I have heard that in C functions should not call each other because they usually have arguments',
  'I refused to learn C plus plus. I saw see-out being shifted left hello world times and gave up',
  'If cavemen had thought of binary we could all count to 1023 on our fingers',
  'If you can't hack it, you don't own it.'
  var randomNumber = Math.floor(Math.random()*factArray.length);
  return factArray[randomNumber];

The only thing left to do is to hook the code up to the Web service framework.


Glitch automatically sets up a library called Express in this project. It essentially is a simple Web server. Once you create the main app object, you can set up routes to have your code execute when someone calls a particular web service. It also includes an object that represents an Alexa service. I didn’t have to write the code to set this up, but here it is:

app = express(),
// Setup the alexa app and attach it to express before anything else.
alexaApp = new"");

// POST calls to / in express will be handled by the app.request() function{
  expressApp: app,
  checkCert: true,
// sets up a GET route when set to true. This is handy for testing in
// development, but not recommended for production.
  debug: true

There are two methods I wanted to provide. One for when someone opens my skill (I called it Hacker Fact, by the way — it gives mildly humorous facts about hacking and related things). The other method will fire when someone says, “Alexa, tell Hacker Fact to give me a fact.” Or anything similar.

That last bit is known as an intent. Intents can have utterances (like “give me a fact”) and they can have slots. I didn’t use any slots (but the weather example did). Using slots you can have some part of the person’s command fed to you as an argument. For example, I could make it so you could say, “Alexa, tell Hacker Fact to give me a fact about Arduinos.” Then I could build the intent so that the next word after it hears “about” is a slot and parse it in my code.

You probably won’t need it, but if you are curious to learn more about Express, check out this video.

The Two Methods

Here are the two methods:

alexaApp.launch(function(request, response) {
 console.log("App launched");
 response.say('Hi from your friends at Hackaday. Ask me for a fact to learn something interesting or possibly funny.');

alexaApp.intent("HackerFact", {
 "slots": { },
 "utterances": [
 "Tell me a hacker fact",
 "Give me a hacker fact",
 "tell me a fact",
 "give me a fact",
 function(request, response) {
 console.log("In Fact intent");
);<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>

Note the “HackerFact” intent has an array of utterances that will be sent to Amazon. You can find the entire HackerFact code online. Don’t forget, you can view the source or remix with the two fish icon at the top right of the page.

All of the code is in the index.js file. There are a few other files, but for this task, you probably won’t make any changes to them other than perhaps changing some text in the package file or documentation.

On to Amazon

Oddly enough, the next part is probably harder. From the front page of the Amazon developer’s site, you’ll want to select Alexa skills and then press the “Add a New” Skill button. A lot of the entries you’ll see have to do with more complex skills. Also, I’m not going to publish my skill, but it will still show up in my account. If you do some paperwork, you can submit your skill for testing with selected users or even publish it outright.

Here’s a rundown of the fields you need to fill in on the Skill Information tab:

  • Skill type = Custom Interaction Model
  • Name = Whatever display name you like
  • Invocation Name = This is what people will ask Alexa to use (e.g., “Alexa, tell Hacker Fact…” would mean my invocation name was Hacker Fact)

I’ve had bad luck, by the way, changing the invocation name after it has been set, so think hard about that one.

The next page (Interaction Model) looks complicated, but it isn’t, thanks to the libraries provided by Glitch. Open your Glitch project. If you are looking at the source, click “show” in the upper part of the screen. The default project causes a data dump to appear on the main page (which, normally, no one sees) that includes the information you need for this page.

The Intent Schema box needs everything after “Schema:” and before “Utterances:” from your main page. That includes the braces. My Intent Schema looks like this:

 "intents": [
 "intent": "HackerFact"
 "intent": "AMAZON.CancelIntent"
 "intent": "AMAZON.StopIntent"

The rest of the page has some lines after “Utterances:” and those lines are what the last box needs. The middle box can remain empty, for this example.

More Steps to Connect Glitch with Amazon

In the Configuration tab, you can select HTTPS and then enter the URL from Glitch. To find that URL, open the project name at the top left of the screen and you’ll see it along with a copy button. Mine, for example, is You don’t allow account linking and you can leave all the optional boxes alone.

On the next screen, you’ll want to pick “My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority” because that’s how Glitch works. That’s all you need on that page.

At this point, your skill should show up on any Alexa associated with your account (including Alexa apps like Reverb on your phone). You can also do tests here in the console to see if things work.

Release the Hounds

This is enough to get your code working with your Alexa. I won’t go into releasing the skill for others to use, but that is an option if you want to keep going on your own. You can use Glitch for other things too, including some Raspberry Pi and a few other IoT-type platforms. If you look around, you’ll probably find something interesting.

Of course, you could set up your own server to do all the things that Glitch is doing for you — maybe even on a Raspberry Pi. You can also let Amazon host your code as a Lambda function (that is, a web service with no fixed web server; see the video, below). If you get a taste for writing skills, the Amazon documentation isn’t bad, but sometimes there’s value to just jumping in and getting something working.

Source link