Idea is to use Alexa to call Google Place search API to get places in London from certain type (ex: hospital, university,..) and get this place information (ex: rating, opening hours,..).
Voice User Interface DiagramUser ask Alexa
Alexa, ask nearest places for a BC
Alexa feedback
founded BC :
name is RNLI Tower Lifeboat Station. rate is 4.4 .
name is Love Success. plc rate is 3.7 .
name is Michael Faraday statue . rate is 5 .
name is IET London: Savoy Place. rate is 4.3 .
name is Abdullah Elias. rate is 5 .Creating Skill
Amazon avail easy tutorials to create skill & lambda function. To create Skill, Lambda function and trigger lambda using the skill follow steps in trivia skill tutorial
Lambda function
I used "google places" API to get nearest locations. You can install Google places package using npm to simplify integration with Google APIs.
Below code explain how you can use the Google npm package to call Google places API
const GooglePlaces = require("googleplaces/index.js");
var googlePlaces = new GooglePlaces(googleAPIKey, "json");
var parameters = {
location: [lng, lat],
rankby: "distance",
type: "hospital", //can be any other location type
opennow: "true"
};
googlePlaces.placeSearch(parameters,
function (error, response) {
console.log('placeSearch error : ' + JSON.stringify(error));
console.log('placeSearch response : ' + JSON.stringify(response));
......
....
}
);
As you see "paramters.opennow = true" to ensure that returned places will be opened at the time of asking.
Example of the Google Places API output will be as below
{
"geometry": {
"location": {
"lat": 32.1815127,
"lng": -81.2324569
},
"viewport": {
"northeast": {
"lat": 32.1822928802915,
"lng": -81.23146351970851
},
"southwest": {
"lat": 32.1795949197085,
"lng": -81.23416148029152
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id": "fdfda64d953dd6df473c57c9d53252d1f2640f09",
"name": "Highlands Clubhouse",
"opening_hours": {
"open_now": true,
"weekday_text": []
},
"photos": [
{
"height": 2340,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/110981917757187861306/photos\">Patty Jenkins</a>"
],
"photo_reference": "CmRYAAAAaH6Sralux0cQdE3AvAkG4KQckvFsPgkl1qPeoeRiTNLfqMkYJP4_MT5-goxp5cGhRM_MHK4vsqON79w5l6koePDAVrv1a1qlUNrq_OnlGhD44JzPyrDT2PXx9quOwxf7EhCak4STHw-qNwuDG1xK1dq5GhT9Zu6V1mpx-7c1fbu89MIQj3-jqQ",
"width": 4160
}
],
"place_id": "ChIJmcxQ1pij-4gRkJHvirG2Zho",
"rating": 3.5,
"reference": "CmRRAAAAFR5g7qwF1p88nXIkD7K2ronJM0Ks2w9E0YA6gDRCnD0bd8dvL1zHagrQYrdZoEV7xMTTuIo5iB6EGAUPw5142gjK19zGzxTWpmXZqnWnKW5ThRLz1fKk8ELqWVccc5jjEhCXZlT7Ctmek7ucZuqEj5cZGhRDbiDGrO6peoCiznEV_3IVsav90A",
"scope": "GOOGLE",
"types": [
"point_of_interest",
"establishment"
],
"vicinity": "210 Highlands Boulevard, Pooler"
}
Google places support many places types such as: universities, hospitals, beauty salon, ...
for more information about google places API, you can check google API documentation to check returned output and calling parameters.
To support SSML response, we use below function
function buildSSMLResponse(title, speechOutput, repromptText, shouldEndSession) {
return {
outputSpeech: {
type: "SSML",
ssml: speechOutput
},
card: {
type: "Simple",
title: title,
content: repromptText
},
reprompt: {
outputSpeech: {
type: "PlainText",
text: repromptText
}
},
shouldEndSession: shouldEndSession
};
}
So Alexa communicates in clear way, for example below is a sample to communicate found places
<speak>founded park : <break time="0.2s" /> name is Victoria Embankment Gardens <break time="0.1s" /> rate is 4.5 . <break time="0.2s" /> name is Senderismo en Londres <break time="0.1s" /> rate is 4.8 . <break time="0.2s" /> name is Whitehall Gardens <break time="0.1s" /> rate is 4.4 . <break time="0.2s" /> name is Bernie Spain Gardens <break time="0.1s" /> rate is 4.2 . <break time="0.2s" /> name is Jubilee Gardens <break time="0.1s" /> rate is 4.5 . </speak>
Certification in UKSkill name is "Nearest Places" and it is applied for certification in both English U.S. & English U.K. languages in all countries & regions where Amazon distributes skills. No difference in Interaction models in English (U.S) & English (U.K).
Skill certified in 9 June 2017 in both US & UK. you can find it here
Future Steps
- Get user address so search result can be customized based on user location
Comments