Alexa voice interface for Toronto Open Data. Ask "Hey Toronto" something and it will display on a paired web page acting as a Kiosk.
Here's the demo video on YouTube.
Ask Hey Toronto…
- where are Parks
- where are Parks near Yonge and Eglinton
- where are Parks near CN Tower
- where are Skating Rinks
- where are Malls
- where are Swimming Pools
- where are Parking Lots
- where are Parking Garages near me
- where are Parking Garages nearby
- where is the CN Tower
- where is the Eaton Centre
When you ask this question, the Kiosk page will update to show the results, something like this:
This project comes complete with source code for both the Alexa Skill Server, and the Web Server, and instructions how to set up everything.
It should be straight forward to adopt this project to other data sets and / or cities. Note however the project is rather sprawling, as there's a lot of moving parts involved in making this work.
On the Web
This project is available under the name "Hey, Toronto" on Alexa.
You can run the Kiosk Web Page at https://hey.homestar.io. Remember you need both of these together.
Technology UsedAlexa
Firebase
Web Development
Server
Data
Open DataThis project is built to showcase Toronto Open Data datasets, available here.
However, the techniques we use should be generally transportable to other cities and datasets. We have code for dealing with data in the following formats.
- XML
- JSON
- KML
- Shapefile
The code is easily adapted to new projects.
As an output format, we basically have made a YAML data format using the standard terms defined by another Open Project, Schema.org.
Data Sets
All the data importers are in ./src. Right now, many of them require a separate shell script to download data, but we hope to integrate that into the Node.JS in the future (basically: download a zip file, extract a specific file, convert it to some more tractable format).
- bicycle-stations - BIXI bike stations
- cultural-hotspots - arts an architecture
- green-p-parking - parking
- intersections - major intersections. We read combinations both ways, so Yonge and Eglinton and Eglinton and Yonge will both be available
- libraries - libaries
- parks - parks, skating rinks, etc.
- places-of-interest - tourism-reated
- places-of-worship - churches, mosques, etc.
These data sets are what let us to queries like Where are Skating Rinks near Yonge and Eglinton.
InstallationEnvironment
Our environment is set up as
- Node JS
- Linux (Centos)
- Apache HTTP
The first is non-negotiable, the other two you can probably subtitute to taste.
Configuration
Do
cp ./config.json.template ./config.json
Fill in all the values.
Libraries
This is needed to parse ESRI shapefile data. It is often used by compile.sh scripts
npm install -g shapefile
This is what we use to run the applications (and to keep them up) in production)
npm install -g pm2
Server Details
Basic Setup
git clone https://github.com/dpjanes/alexa-opendata
npm install
cd ./web
npm install
npm run build
Open Data
Note that we ship with all the compiled data, so you don't need to do this!
First, go to ./src and run the compile.sh file in all subfolders (that have them).
Compile data into our standard format
node ./bin/compile-dst
Make Alexa Skill data
node ./bin/create-slots
Run Servers
pm2 start ./bin/server-alexa.js
pm2 start ./bin/server-web.js
Apache
See the README in ./apache/README.md about how to set up Apache. If you're not using Apache, you can still probably use this as a guide.
Firebase SetupCreate New Project
- go to the Firebase Console
- click on Create New Project
- enter a name for the project, select a payment plan, click on Create Project
Get Settings
This allows our code to access firebase (mostly).
- select your project (if not already selected)
- click on Add Firebase to your web app
- copy the JSON object to config.json in the home folder of this project, specifically in the firebase section. It will look something like this
{ … "firebase":
{ "apiKey": "AIXXXXXXXXXXXXXXXXXX",
"authDomain": "alexa-opendata.firebaseapp.com",
"databaseURL": "https://alexa-opendata.firebaseio.com/",
"storageBucket": "alexa-opendata-uiueieui.appspot.com" },
… }
Set up Authentication Methods
This allows users to log in.
- click on Authentication (left hand side)
- click on Set up Sign-in Method
- enable Google sign in. If you want to add other sign in methods you'll have to look at web/src/actions/auth
- set up the services you want, e.g. Twitter, Facebook, Google…. You'll have to consult the documentation for each of those services to get API keys. Except for Google, which you can do with a click
Add Ouath Redirect Domain
Firebase will only allow named hosts to authenticate. In our case, this is hey.homestar.io.
- click on Authentication (left hand side)
- click on Set up Sign-in Method
- click on Add Domain (further down the page)
- add your domain name.
Firebase-admin
This allows our code to verify that a token coming from Firebase is actually from Firebase. We use this to exchange a short lived token for a longer-lived on that we use to identify users for Alexa.
- follow these instructions
- save the downloaded file to firebase-admin.json in the root folder of this project
Database Rules
- click on Database (left hand side)
- click on Rules
- add the following rules
{ "rules":
{ "stations":
{ ".read": true, "$station" :
{ ".write" : "$station === auth.uid", ".read" : true
} } } }
These rules allow authenticated users to modify data only under /stations/thier-uid
AlexaThis is a fairly standard Alexa Voice Skill project, of which there's quite a bit of instruction for on the web.
We'll just provide the main details here:
- Create a New (Custom) Skill. It does not use the Audio Player
- In the Interaction Model tab: From ./skill folder, copy the SampleUtterances.txt, the What and Where slots, and the IntentSchema.json
- In the Configuration Tab, select HTTPS and add your URL. In our case, this is https://alexa-opendata.homestar.io/request
- In the Configuration Tab, turn on Account Linking. Add an authorize URL (ours is https://hey.homestar.io/authorize ), and make a client-id (ours in alexa-openid). Copy the client-id and one of the redirect urls to ./config.json
- In the SSL Certificate field, assuming you used Let's Encrypt, select My development endpoint has a certificate from a trusted certificate authority.
If all your servers are up and running, you should be ready to test
Comments