Inspiration

Most of have two or three places we travel to on a somewhat regular schedule (work, school, gym, etc). Most times, we understand traffic patterns and know when to leave in order to get there on time.

However, every once in a while, there is an accident or traffic delay that impacts our ability to get to the location on time.

I wanted to build a skill that:

  1. allows me to save multiple locations ("base" Alexa functionality only lets me save one location)
  2. lets me save context about the travel time for a location (I want to be alerted about the correct traffic patterns at the appropriate time)
  3. proactively lets me know if there is a traffic delay (but only notifies me when there is a delay; I don't need to know if traffic is normal)

Note 1: I would think that these are simple "base" functionality features that could be built into Alexa (especially the proactive notifications). Maybe this will be a later release (making my skill obsolete!!!).

Note 2: I understand that there are some applications that already do what I've outlined above. My issue is that:

  • often, these apps send a reminder regardless of the traffic. For me, a daily alert saying that traffic was normal would become white noise, and I'd probably start to ignore the reminders
  • These alerts often "ring" after I am in the car, or after I am on my way... meaning that I'm already going to be late because I didn't leave early enough
  • Most of these alerts 'ring' on a cell phone. My skill sends message via cell as well, but a later enhancement will probably move the alerting functionality from SMS messages to Alexa Proactive Events. (there is not a "traffic delay" schema for events yet; I plan to request this on the Alexa uservoice website).

What it does

Get There On Time is a relatively straight-forward application. It:

  • Ask for a destination
  • Asks for days and times you typically travel
  • Determines the typical time it takes to travel to the destination

When the user opens the skill, it does one of two things:

Normal use:

  • Give a high level overview of the traffic for all saved locations (based on the typical travel time)

If a saved commute is supposed to start within 15 minutes:

  • Provide detailed route options and maps
  • Sends the map to the device (either via an Alexa card or SMS - if the user have provided a mobile number)

In addition, I wanted to remove the "friction" of having to remember to open skill to get traffic, so I decided to implement proactive alerting (via an In Skill Purchasing subscription). This way, the user does not have to remember to open the skill in order to get timely information.

How I built it

The Alexa Skill: All location, distance, map, photo, traffic, and travel duration information is obtained by Google Map APIs. These apis allow me to:

  1. Search for a location
  2. Provide results and get confirmation from the user
  3. Determine the typical traffic for a given day and time
  4. Determine real time traffic patterns
  5. Proive maps of the location and of the trip
  6. Provide images of the location

Screenshot

Screenshot

I also used moment.js for time manipulation and standard AWS services to communications (SNS), compute (Lambda), memory (DynamoDB) and content management (S3 and CloudFront).

Proactive Alerting An "out of skill" lambda function runs every 10 minutes and checks traffic for all commutes that are 15-30 way from starting (e.g. - if I travel to Starbucks every Tuesday at 8AM, then this function will start to check traffic on Tuesday at 7:45AM).

Challenges I ran into

Note 3: Typically I include an arch diagram in these write ups; this time I really wanted to deep dive on the gotchas... maybe this will help other developers.

Timeouts: As mentioned above, I used Google APIs for almost all data searches and map renderings. Every once in a while, the API would not return within the 8 seconds that an Alexa skill is "active"... so I had to build a mechanism to handle timeouts. I ended up using promises and promise.Races to send an error message if the search result did not return in 7.5 seconds.

Timeout code snippet

Images: Typically, I just use free images from one of a number of free image services and icon services (that often require attribution). I decided to buy icons and background images for this skill (since I was incorporating ISP). This was a huge timesaver and something I'll probably do in the future.

Alerts/Reminders/Proactive Events I really wanted to use Alexa Proactive Event functionality in this skill; unfortunately, this API is pretty locked down (messages have to fit one of 5-6 schemas, there isn't one for traffic delays). I though about using Alexa reminders, and dynamically updating them (so that it "alarmed" as needed with the correct information).. however, that wasn't as "clean" of a solution as I would have liked.

Ultimately, I decided to send alerts via Mobile SMS, with the plan to move to Proactive Events when a traffic delay schema is available. Using Proactive Events also gives me the ability to send the message to the Alexa device (versus the cell phone).

Multi-Touch Information (Calendars, Time, etc): There isn't functionality for a full fledged "keyboard" (today) in APL, so I knew I couldn't ask the user to input the location via typing. Days and Date/Time are a little simpler to input, so I was able to use SetState logic to "highlight a 'button' and SendEvent logic to send the "date part" value (the day, the hour, or the minute) to my lambda skill. After I get all the date time components, I re-render the screen with the new (or updated) commute day(s) and time.

Touch Control

What's next for Get There On Time

  • Asking for and enabling proactive alerts for traffic delays
  • Refine the icons and images
Share this project:
×

Updates