I hate creating Alexa skills. What should be a 3-click process inevitably ends up requiring trips to multiple websites, to set up weird parameters, and reading outdated tutorials for obsolete libraries.
So this is how to create a self-hosted Skill, using PHP. It runs on your own server and doesn’t require any interaction.
At a basic level, all your website has to do is spit out a piece of JSON for Alexa to read out.
<?php // Set the correct header for JSON data header('Content-Type: application/json'); // Set the response $response = [ "response" => [ "outputSpeech" => [ "type" => "PlainText", "text" => "I'm a little teapot" ] ] ]; echo json_encode($response);
This is perfect for when you have a simple query – “Yo! Alexa! Bus time?” – one question, no parameters.
OK, you can make sure that the request genuinely came from Alexa, and do all sorts of certificate checks. But why bother? Totally unnecessary for a personal skill.
Obviously, you can do some programming make the text say
That was easy, right?
The Amazon Side
OK kid, this is where it gets complicated.
For this you will need an Amazon developer account. Getting one is beyond the scope of this tutorial.
Click the “Create Skill” button.
Give your skill a name. It defaults to USA! USA! USA! English – even though Amazon knows your location and the location of your Echo. If you think AI is hard, that ain’t nothing compared to localisation.
You need to select a Custom skill and to “Provision your own endpoint”.
If you try to use AWS Lambdas you’ll be in for a world of pain. Don’t even bother – they are a nightmare for a beginner to use.
Now scroll all the way back to the top of the website to click the “Create Skill” button. You’d think that after filling in a form, the “next” button would be at the bottom. But that’s too easy. If you think AI is hard, that ain’t nothing compared to designing an easy to use form.
We’re going to choose the “Start From Scratch” template.
This has nothing to do with the Scratch programming language. Which is a shame, because Scratch is a great language and well designed for complex voice interaction models.
Before doing anything else, set up your “endpoint”. This is the website where you uploaded your PHP file.
Your website needs to support https – you may need to change the certificate type on this page if Amazon has difficulties with it.
Hit “Save Endpoints” – again, it is at the top of the screen. Because people naturally work from the bottom of the form to the top of the form.
Next up, we need a default intent. It doesn’t really matter what you put in here. This is not a complex skill which can take multiple routes. We just want something to happen whenever it is launched.
Because Alexa isn’t really an AI – we have to give lots of “sample” utterances. So, if you want bus times, you might add “next bus”, “buses”, “when is my bus” – and every variation you can think of.
Now hit “Build Model” at the top. Once that’s done, go to test.
Set the dropdown to “Development”.
That’s it! You’re finally done! You can test the skill by either typing “whatever” into the text box, or by saying “Alexa! Whatever.”
Alexa will read out whatever is in your PHP script.
I wish it were easier. Why can’t I just say “When I ask this question, reply with the data from that website.” Sites like IFTTT and Zapier make it so easy to create services – I wish there was a Voice Assistant which was easy to make skills for.