/cta-bus-tracker

action on google to track cta buses

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Actions on Google: Windy City Bus Tracker

Prerequisites

  1. Node.js and NPM
  2. Install the Firebase CLI
    • We recommend using MAJOR version 8 , npm install -g firebase-tools@^8.0.0
    • Run firebase login with your Google account
  3. Get an API key on the CTA website

Setup

Actions Console

  1. From the Actions on Google Console, New project > Create project > under What kind of Action do you want to build? > Custom > Blank project

Actions CLI

  1. Install the Actions CLI
  2. Navigate to sdk/settings/settings.yaml, and replace <PROJECT_ID> with your project ID
    • To find your project ID, click the three dots > Project Settings
  3. Navigate to the sdk/ directory by running cd sdk from the root directory of this project.
  4. Run gactions login to login to your account.
  5. Run gactions push to push your project.
  6. Update settings.yaml (or Settings in the Actions Console) to fix errors
    • e.g. displayName key must be unique from other Actions).

Firebase Functions

  1. Navigate to the functions directory.
  2. Run npm install
  3. Run firebase use --add and follow the prompts to use your project.
  4. Run npm run deploy. Follow console instructions to fix errors (i.e. update your billing plan).
  5. Navigate to functions/package.json and update the name key with your project name.
  6. Configure your functions environment by running firebase functions:config:set ctabustracker.key="THE API KEY" with your API key from the CTA
  7. Run npm run deploy again. Copy the function URL and paste it in baseUrl key in sdk/webhooks/ActionsOnGoogleFulfillment.yaml
  8. Navigate to the sdk/ directory and run gactions push.

Running this Sample

  • Run gactions deploy preview to deploy your project. Alternatively, go to the Actions Console, refresh the page and click on the "Test" tab.
  • You can test your Action on any Google Assistant-enabled device on which the Assistant is signed into the same account used to create this project. Just say or type, “OK Google, talk to my test app”.
  • You can also use the Actions on Google Console simulator to test most features and preview on-device behavior.

Developing this Sample

Deploying your function every time you update code gets annoying. So here is how you test locally. It is recommended to create another project solely for testing by following the instructions above.

  1. Run npm i ngrok -g.
  2. Navigate to the functions/ directory.
  3. firebase functions:config:get > .runtimeconfig.json
    • If using Windows PowerShell, replace the above with: firebase functions:config:get | ac .runtimeconfig.json
  4. Run npm run serve. Note the port on which the function is running, usually 5001
  5. Run ngrok http <PORT> with the port number.
  6. Copy the HTTPS forwarding URL and paste it in baseUrl key in sdk/webhooks/ActionsOnGoogleFulfillment.yaml
  7. Run gactions push from the sdk/ directory.
  8. Test code live from the Actions on Google Console simulator.

When Finished

  1. Replace the baseUrl value with the original Firebase function URL
    • You can find this in your Firebase Console if it doesn't appear in your own.
  2. Run npm run deploy from the functions/ directory.

References & Issues

Contributing

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.