Are you ready to ask your Amazon Echo, "Alexa, where's my bus?"
This project is an implementation of the OneBusAway open-source platform for real-time transit info for Amazon's Alexa Voice Service.
To enable this skill on your Alexa device, you can say, "Enable OneBusAway skill."
You can also search for and enable skills in the Alexa app:
Just say "Alexa, open OneBusAway" to get started. You'll set your city and favorite stop, using the stop number. Then, just say "Alexa, open OneBusAway" to get arrival times for your favorite stop. You can find your stop number on the placard in the bus zone, in your OneBusAway mobile app, or on your agency website. If you have trouble finding your stop number, see our guide for "Finding your stop number".
Other features - say Alexa, ask OneBusAway to...
:
...filter routes
to filter out arrivals for particular routes for your currently selected stop...enable clock times
to announce times in a clock format like "at 10:25am" instead of "in 5 minutes"...set my stop to X
to change your stop to the specified number...set my city to X
to change your city to the specified city...repeat
to repeat the last message...enable experimental regions
to enable regions that may be unstable and without real-time info. Note that you first need to set up the skill with a non-experimental region and stop that are supported by default before invoking this command - see this post for details.Refer to interaction model/utterances.txt
for the full list of spoken phrases we support.
Our user interface flow diagram also defined how you can interact with the skill.
The OneBusAway skill is currently available in the following cities:
See OneBusAway Deployments for more information about available OneBusAway regions.
See our Privacy Policy to better understand what information the OneBusAway Alexa skill uses when you request transit arrival information.
Want to make OneBusAway Alexa better? We welcome collaboration! See our Contributing Guide for more details.
The application backing the skill was designed to run in AWS.
The set up process will be a bit circuitous, because, for security reasons, you want Lambda to run your code only if triggered by Alexa, rather than some random Internet visitor or script kiddie. To do this, we must create a skill first, and then supply its unique skill id to Lambda. But, to create a skill, a backing Lambda function should already be deployed. This is resolved by deploying a placeholder Lambda function first, and updating it later.
Therefore, the process is as follows:
aws/cloudformation/onebusaway.template
.You can examine AWS resources created from this template on the Resources tab.
Note that two distinct sets of AWS access credentials are being generated: {lambdaDeploymentAccessKey}
and {lambdaDeploymentSecretKey}
are for deploying Lambda functions, whereas {appExecutionAccessKey}
and {appExecutionAccessSecret}
are for running the application.
You can also use CloudFormation from command line with AWS CLI.
mvn package
. Look for "BUILD SUCCESS". Resulting JAR is target/onebusaway-alexa-1.0-jar-with-dependencies.jar
Upload to Amazon Lambda with:
mvn lambda:deploy-lambda \
-DaccessKey={lambdaDeploymentAccessKey} \
-DsecretKey={lambdaDeploymentSecretKey} \
-Ds3Bucket={lambdaDeploymentS3Bucket} \
-Dregion=us-east-1 \
-DlambdaRoleArn={lambdaExecutionRoleARN}
...where {lambdaDeploymentAccessKey}
, {lambdaDeploymentSecretKey}
, {lambdaDeploymentS3Bucket}
and {lambdaExecutionRoleARN}
are values generated by CloudFormation during AWS infrastructure set up.
From the AWS Console > Lambda, open the newly created Lambda function and add a Trigger (Event Source) of type Alexa Skills Kit
.
Note the ARN of the Lambda function at the top right corner of the screen. You will use it to set up a new Alexa Skill in the next section.
See the lambda maven plugin homepage for more information on deploying.
Go to the Amazon Developer Console > Alexa
Add a new skill. Set Skill Type to Custom Interaction Model
, set Invocation Name to "one bus away". Name can be anything since this is your development version.
Paste the contents of file interaction model/newSchema.json
into "JSON Editor" under interaction model.
Save and build the model.
On Endpoint page set up your endpoint by plugging in your Lambda function's ARN. Go Next. That creates the skill, however it is not functional yet.
At the top of the screen note application ID. You will use it to configure Lambda code.
To set up your skill to support personalization, you must follow these steps.
Set up your skill to request personalization permissions.When you create or edit a custom skill, you can turn on permissions for Skill Personalization in the developer console.
Set up your skill service to use personalization in its responses, if Personalize skills is toggled on for a recognized user.
Make sure your skill service gracefully handles those cases where a user is not recognized, or a user refuses permission for personalization.
ask api get-skill -s {skillId} > skill.json
to get your skill schema in skill.json
file, add the event subscription JSON blob below to skill.json, and run
ask api update-skill -s {skillId} -f skill.json > skill.json
to update the schema, reference: Add Events to Your Skill
Event subscription JSON blob.
"event": {
"endpoint": {
"uri": "{lambdaExecutionRoleARN}"
},
"regions": {
"NA": {
"endpoint": {
"uri": "{lambdaExecutionRoleARN}"
}
}
},
"subscriptions": [
{
"eventName": "SKILL_ENABLED"
},
{
"eventName": "SKILL_DISABLED"
}
]
}
Example of skill schema with event subscription.
{
"manifest": {
"apis": {
"...":"..."
},
"events": {
"subscriptions": [
{
"eventName": "SKILL_ENABLED"
},
{
"eventName": "SKILL_DISABLED"
}
],
"regions": {
"NA": {
"endpoint": {
"uri": "{lambdaExecutionRoleARN}"
}
}
},
"endpoint": {
"uri": "{lambdaExecutionRoleARN}"
}
},
"manifestVersion": "x.x",
"permissions": [
{"...":"..."}
],
"privacyAndCompliance": {
"...":"..."
},
"...":"..."
},
"...":"..."
}
}
src/main/resources/onebusaway.properties
with the following parameters:skill-app-id-development=
aws.key-id=
aws.secret-key=
googlemaps.api-key=
onebusaway.api-key=
Fill in the values:
skill-app-id-development
is Alexa Skill ID from previous step
aws.key-id
and aws.secret-key
are {appExecutionAccessKey}
and {appExecutionSecretKey}
respectively as generated by CloudFormation
googlemaps.api-key
Google Maps GeoCoding API Key which can be obtained from Google Developers
onebusaway.api-key
can be obtained from your local OBA region. Typically, you can use TEST
while are you waiting for a key.
mvn package
.CAUTION: Every time you re-deploy to Lambda using the lambda-maven-plugin
, you must
manually re-add "Alexa Skills Kit" as the function's Trigger. Support for Event Source configuration is coming.
For now, you do not need to do this if you deploy your code through the Lambda UI in AWS Console.
Don't have an Amazon Echo? No worries, there are a few options.
Just remember to log in using the same Amazon account that you've used above to set up the skill.