Note: The rest of this readme assumes you have your developer environment ready to go and that you have some familiarity with CLI (Command Line Interface) Tools, AWS, and the ASK Developer Portal.
-
/lambda/custom
- Back-End Logic for the Alexa Skill hosted on AWS Lambda -
/lambda/custom/resources
- Language specific speech response -
/models
- Voice User Interface and Language Specific Interaction Models -
skill.json
- Skill Manifest
-
Node.js (> v8.10)
-
Register for an AWS Account
-
Register for an Amazon Developer Account
-
Install and Setup ASK CLI
-
Rocket Chat Server updated to Release 1.0.0-rc3 or later
- Clone the repository.
$ git clone https://github.com/RocketChat/alexa-rocketchat.git
- Navigating into the repository's root folder.
$ cd alexa-rocketchat
- Install npm dependencies by navigating into the
lambda/custom
directory and running the npm command:npm install
$ cd lambda/custom
$ npm install
-
If you already have an Alexa Skill deployed, Open
./skill.json
file and add the ARN of your AWS Lambda function. -
If you're about to deploy your Alexa Skill for the first time, cut the following piece of code from the
./skill.json
file,
"permissions": [
{
"name": "alexa::devices:all:notifications:write"
}
],
"events": {
"publications": [
{
"eventName": "AMAZON.MessageAlert.Activated"
}
],
"endpoint": {
"uri": "your-arn-here"
},
"subscriptions": [
{
"eventName": "SKILL_PROACTIVE_SUBSCRIPTION_CHANGED"
}
],
"regions": {
"NA": {
"endpoint": {
"uri": "your-arn-here"
}
}
}
}
- Go to Deployment and complete the deployment steps and also configure the account linking. Once done complete the following steps.
- Paste the above piece of code back to your
./skill.json
file. Add the ARN of your AWS Lambda function you just deployed in place ofyour-arn-here
. - Deploy the changes.
$ ask deploy
-
Go to your Alexa App and enable notifications for this skill. New users of the skill will be the shown the permissions settings while enabling the skill itself.
-
Setup a notifications microservice following the instructions in Rocket Chat Alexa Skill Notifications. Also it will be worth checking out this video to get insights Alexa Notifications with Proactive Events - Dabble Lab #125.
-
WE ARE DONE! To test the skill, go to Testing.
ASK CLI will create the skill and the lambda function for you. The Lambda function will be created in us-east-1 (Northern Virginia)
by default.
- Make sure you are at your
alexa-rocketchat
top level project directory, then deploy the skill and the lambda function in one step by running the following command:
$ ask deploy
- After Deploying go to lambda console and set Environment variables values.
e.g:
-
SERVER_URL https://yourservername.rocket.chat
-
OAUTH_SERVICE_NAME (The name of the Custom OAuth you setup in next step)
-
DDB_NAME (The name of the Dynamo DB table being used by your skill)
-
Then go to the IAM console and add policies to access DynamoDB and Cloudwatch to the role for this lambda function.
-
Go back to Configuring Notifications to complete the rest of notification setup or proceed with configuring account linking steps if you're already done.
-
Login to Alexa Developer Console, click on the Rocket.Chat skill on the list, and go to Build section on top.
-
Click on Account Linking on the bottom left.
-
Toggle the Do you allow users to create an account or link to an existing account with you? button. Leave Allow users to enable skill without account linking as it is. Select auth code grant.
-
Now we need to fill up the Authorization URI, Access Token URI, Client ID, Client Secret which we will generate on our rocket chat server.
-
Note you need to be admin of the server to proceed with the further steps.
-
In a new tab go to your Server -> Three Dot Menu -> Administration.
- Click on OAuth Apps.
-
Click on New Application on top right. Now we need to give it an Application Name and a Redirect URI.
-
For Application Name use "alexa". This can be anything else as well. And for the Redirect URI, go back to Amazon Developer Console Account Linking page and at the bottom of the page you'll find some redirect URLs.
Copy https://pitangui.amazon.com/api/skill/link/YOURVENDORID or https://layla.amazon.com/api/skill/link/YOURVENDORID or https://alexa.amazon.co.jp/api/skill/link/YOURVENDORID and paste it in the Redirect URI field. They work according to the locale of your developer account, so try another if one of them doesn't work. Click on save changes.
-
You'll see it automatically generating Client ID, Client Secret, Authorization URL, and Access Token URL. Now copy these from the oauth app page and paste it in the Client ID, Client Secret, Authorization URL, and Access Token URL fields on the amazon developer console account linking page.
-
Choose "HTTP Basic" for Client Authentication Scheme and leave Scope, Domain List and Default Access Token Expiration Time empty. Click on Save on top.
-
We are done on setting our OAuth App which will give us the access token to use for logging in. But for that we need to also enable custom oauth login for our server which we will do in the next steps.
-
Go to your Server -> Three Dot Menu -> Administration. Scroll down on your left and select OAuth and on top right click on Add custom OAuth.
-
Give a unique name in lower case for the custom oauth. For example enter "alexaskill".Click on Send. Set this name in the lambda environment variables for OAUTH_SERVICE_NAME.
-
You will now be provided a few fields some of which will be prefilled. We only need to change a few. First change the Enable to true. In the URL enter https://yourservername.rocket.chat/api/v1.
-
Finally at the bottom switch Merge users to true. We don't need to make any other changes here.
-
Click on Save Changes on top. We are done with setting up the account linking.
-
Go back to Step 4 of Configuring Notifications and complete the rest of notifications setup.
-
Before testing, you must make sure that Account Linking has completed. Go to alexa.amazon.com or your alexa app and click account linking to complete the link.
-
To test, you need to login to Alexa Developer Console, and enable the "Test" switch on your skill from the "Test" Tab.
-
Once the "Test" switch is enabled, your skill can be tested in the Alexa skill simulator or on devices associated with the developer account as well. Speak to Alexa from any enabled device, from your browser at echosim.io, or through your Amazon Mobile App and say :
Alexa, start rocket chat
With this setup, develper can run the backend code of the skill in the system itself, leading to faster development.
Note: The below setups are optional and is not required for the code to run in aws lambda.
-
Navigate to
./lambda/custom
folder and make a new file named .env -
Add the following to .env file
ACCESS_KEY_ID=<your aws account access key ID>
SECRET_ACCESS_KEY=<your aws account secret access key>
SERVER_URL=<rocket chat server url>
OAUTH_SERVICE_NAME=<oauth service name>
DDB_NAME=<dynamo table name>
CUSTOM_LOG_URL=<custom logger url(optional parameter)>
-
From
./lambda/custom
folder, runnpm start
to start the server at port 3000. -
Install
ngrok
, then in a new terminal runngrok http 3000
, copy the https forwarding link. -
In the build section of the Alexa Developer Console, go to endpoint submenu in the sidebar and set the Service Endpoint Type to HTTPS.
-
In the default region input box, paste the link from step 4 and set the drop down to "My development endpoint is a sub-domain of a domain that has wildcard certificate from a certificate authority" option, save the changes.
./skill.json
Change the skill name, example phrase, icons, testing instructions etc ...
See the Skill Manifest Documentation for more information.
./lambda/custom/index.js
Add new handlers for intents, modify intent logic, enhance the functionality of the source code to customize the skill.
./lambda/custom/resources/*.json
Modify messages, and other strings to customize the skill responses. Repeat the operation for each locale you are planning to support.
./models/*.json
Change the model definition to replace the invocation name and, if necessary for your customization, the sample phrases for each intent. Repeat the operation for each locale you are planning to support.
Rocket.Chat API Documentation
The REST API allows you to control and extend Rocket.Chat with ease - REST API Documentation
Axios Documentation
Promise based HTTP client for the browser and node.js - Github Page
Jargon Documentation
The Jargon SDK makes it easy for skill developers to manage their runtime content, and to support multiple languages from within their skill - Github Page
Slot Type Reference
The Alexa Skills Kit supports several slot types that define how data in the slot is recognized and handled - Official Documentation
-
Keep sample utterance minimal.
-
Make sure you have included the values that are required to send to the API as slots in the sample utterance.
-
Use only custom slots and include real examples from Rocket.chat for Natural language training.
-
Include as many slot values as you can. More the merrier.
Keep an eye on our issues. We are just beginning and will surely appreciate all the help we can get. All ideas are welcome.
Feel free to join the discussion in our Alexa channel - Rocket.Chat Alexa Channel