This project is a PHP library meant to be used with the Alexa Skill Builder to rapidly build Alexa skills without needing to jump into Java or set up a server that runs node.js.
Here's a simple Hello World skill made with it:
<?php
// Include the library
require __DIR__ . '/alexa-endpoint/autoload.php';
// Import classes
use MayBeTall\Alexa\Endpoint\Alexa;
use MayBeTall\Alexa\Endpoint\User;
// Sets everything up.
Alexa::init();
// User launched the skill (Alexa launch Hello World).
Alexa::enters(function() {
// Say something and close the app
Alexa::say('Hello world!');
});
// User triggered the 'HelloWorldIntent' intent from the Skill Builder
User::triggered('HelloWorldIntent', function() {
// Say something and close the app
Alexa::say('Hello world!');
});
// User exited the skill.
Alexa::exits(function() {
/**
* Alexa will not say anything you send in reply, but it is important
* to have this here because she will give an error message if we
* don't acknowledge the skill's exit.
*/
});
Read the library's documentation here.
This project is intended to be used by developers looking to have fun with Alexa. Maybe to intergrate her with some APIs, like Toggl's or Jira's. I wouldn't trust it for anything big - and I created it.
You need:
- An Amazon Developer Account.
- WAMP/MAMP/LAMP or a server.
- A SSL (HTTPS) connection accessible from the internet.
- Basic knowledge of PHP.
- Basic understanding of the command line and how to run programs from it (for ngrok).
No worries. We have a couple options.
You can use ngrok to create an SSL connection that Amazon can connect to.
You can get a real SSL certificate, or create a self-signed certificate for development.
Note: I've never used that website. I literally just found it and thought it would be the easiest way for you do make one if needed.
Alright, we got everything we need? Good.
- Download or clone this repo.
- I hope you know how to do that.
- Put the project in your enviroment.
- I really hope you know how to do that.
- Go to
HelloAlexa.php
with your browser.- You should see 'Application not authorized.' and that is great.
- Set up SSL
- Download ngrok.
- Tell it to forward your local dev url. Check out their documentation
- Go to the link ngrok supplies and try reaching
HelloAlexa.php
again.- See the same message? Good. We can move on.
- Follow step 1 in this guide by Amazon on creating a skill.
- The 'Name' and 'Invocation Name' can be anything they allow. I used
HelloWorld
andhello world
.
- The 'Name' and 'Invocation Name' can be anything they allow. I used
- Use the Skill Builder Beta.
- Click 'Code Editor' on the left hand navigation.
- Drag and drop
HelloAlexa.json
, or paste in the code from it. - Click "Save Model".
- Click "Build Model"
- Wait for it to build.
- In the Skill Builder, go to Configuration.
- Choose 'HTTPS'
- Click a location
- Paste the HTTPS url, ending with HelloAlexa.php.
- Click next
- Click 'My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority' (or self-signed, if you did that).
- Click next.
- Before we use Alexa, let's test using the 'Service Simulator'.
- Type 'launch helloworld' (or whatever you used) and click 'Ask HelloWorld'
- You should get back some JSON with 'Hi, what is your name?' somewhere inside.
- Your skill should be enabled now and your Alexa will have automatically installed the skill.
- Say 'Alexa launch hello world'.
- Follow prompts. Or don't.
- Say 'Alexa, tell hello world my name is MayBeTall'
- This jumps directly to the NameIntent, skipping the first prompt.
- Say 'Alexa, tell hello world yes'
- This just skips to the CoffeeIntent, which isn't meant to be jumped straight to, but we can anyways.
Seriously, connect Alexa to the API of some website you love to use (like GitHub) and see how amazing it is to build your own intergrations. Read the library's documentation here.