Alexa: Check out Salesforce’s New Geocoding Features
A few weeks ago, I was at my brother-in-law’s house checking out their Amazon Echo. The kids were having a blast playing tunes and adding items to the shopping list. Okay, maybe it wasn’t just the kids. I picked up an Echo and began tinkering with Alexa, Echo’s version of Siri.
Alexa comes with a standard set of “skills” you can interact with. The skills are kicked off by asking Alexa a question, such as “Alexa did the Twins lose yet again?” or “Alexa, did Blair Walsh miss another field goal?” In addition, Amazon provides a developer account and portal for creating custom skills. Enter Salesforce’s new automatic geocoding feature.
One of my favorite features of the Summer release is the ability to automatically geocode standard Account, Contact, and Lead fields. All in all, you can run a Data.com clean rule to automatically set latitude and longitude for four different standard addresses. If you’re interested in learning more on the geocoding feature, see the following article on the release notes here: https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_general_geocodes_aloha.htm
Side Note: If you need to set custom addresses or automatically geocode custom latitude and longitude coordinates, consider running a trigger or process on a mock/dummy Account, Lead, or Contact and then carry over the coordinates to custom latitude and longitude fields.
Here’s where the light bulb went off. Wouldn’t it be cool (maybe it’s just me) if you could ask Alexa when exactly you had to leave by, to make your next meeting on time? Well, now you can with a custom Alexa skill, that queries for your next event/meeting in Salesforce, and then uses the Google Maps Distance Matrix API (https://developers.google.com/maps/documentation/distance-matrix/intro) to calculate the travel time.
Here’s how it works:
- The automatic geocoding Data.com cleaning rule is enabled for accounts.
- An account is created with a MailingAddress specified. When the account is saved, the latitude and longitude are automatically populated.
- An event of type “Meeting” is assigned to you, and also relates to the account created in Step 2.
- You call an “utterance” by saying “Alexa: connect to Salesforce”.
- After Alexa responds with “Connected to Salesforce,” you issue a secondary utterance “Get Next Event”.
- This calls a node.js service hosted on Heroku.
- Heroku uses the nForce toolkit to call a custom Apex REST service in Heroku, which responds with your next event, including the latitude and longitude of the account associated with the event.
- The node.js service then calls the Google Maps Distance Matrix API with the latitude and longitude, and calculates the travel time.
- The node.js service then returns the information via the callback URL set when setting up the skill in your Amazon / Alexa developer account.
Looking to implement your own custom Salesforce Alexa skill? You’ll need the following:
- A Salesforce org (preferably a developer org: https://developer.salesforce.com/signup)
- A Heroku account (sign up for a free at https://www.heroku.com)
- A developer account with Amazon (https://developer.amazon.com)
- The heroku toolbelt
- At least a basic knowledge of JS
In order to implement the custom skill, I followed the excellent “Echo Case Control” tutorial from Salesforce Developer evangelist Josh Birk (@joshbirk on twitter): https://github.com/joshbirk/EchoCaseControl. Combining this with the node-googlemaps project (https://github.com/moshen/node-googlemaps), I now had the following app: https://github.com/dancinllama/EchoCaseControl
After pushing the app to heroku, I could now ask Alexa to connect to Salesforce and get my next event:
Have an idea for your own Salesforce and Alexa skill? Feel free to fork my project (or Josh’s project) above and tinker away.
Contact Us Now!
Looking for a trusted Salesforce Partner to help you get results? You’re in the right place! We would love to hear from you!