HERE Location Services with Alexa

Lynn Langit
6 min readFeb 18, 2019

Written by Jessica Ellis & Lynn Langit

Learning API Programming

In the fourth episode of this series, we’ll review a tutorial to create a location-aware AWS Alexa Skill in which you search for nearby places of interest. To build this sample, you call two HERE Location Services APIs (Geocoder & Places) via an AWS Serverless Application Repository application. Additionally, you use the AWS Marketplace to work with the HERE JavaScript API. The full tutorial is here .

Location enabled Alexa Application architecture

If you are new to building apps on AWS with HERE Technologies APIs, then you may wish to read previous parts of this series for additional context:
Part 1. Use HERE APIs and AWS S3 —
here
Part 2. Use HERE Geocode app from AWS Serverless App Repository (SAR) —
here
Part 3. Use HERE APIs and AWS SAR to build a web application —
here

Building a location-aware Alexa Skill

Alexa devices

Alexa is a voice-activated, interactive AI bot, that lets you speak with Amazon home devices. Alexa Skills are applications that give Alexa devices customized capabilities, such as letting a user speak to more devices and websites.

In the tutorial you use the HERE Technology REST APIs to create a location-aware Alexa Skill. Using this skill you can search for nearby places. For example: “Alexa, show me nearby Sushi in Seattle.”

Setup Services

First, you set up your service access. In order to build this example application yourself, you sign up for the required services.

For testing, you will likely be able to use the HERE Technologies and AWS FREE service tiers. You will also use an Alexa Developer account.

1. Create your HERE developer account
2. Create your AWS account — ideally you use a dedicated AWS account for training & development.
3. Create your ALEXA developer account

Create an Alexa Skill

To start, you create a new Alexa Skill. To do this, log in to the Alexa Developer console and choose ‘Skills’ from the dropdown menu located under ‘Your Alexa Consoles’ and click ‘Create Skill’. Choose a short name for your skill (such as ‘HERE places’), then select ‘Custom model’, and click ‘Create skill’.

After clicking ‘Create Skill’ you are directed to the skill’s console page, in the bottom left hand corner, click on the JSON Editor to open it. The tutorial provides code to paste into the JSON editor which will create the required invocation, intent and slot objects.

  • An invocation is a phrase to launch the Alexa Skill, ex. ‘HERE Places’
  • An intent is a phrase to launch a function within the Alexa Skill, ex. ‘Show me sushi near Seattle.’
  • A slot is a parameter within an intent, ex. ‘sushi’ is the place of interest & ‘Seattle’ is the location for the search.

After pasting the code, click ‘Save Model’ andBuild Model’. Look for the green ‘Build Successful’ window (example shown below).

Alexa Developer Console JSON Editor view

Create an AWS Lambda with the AWS SAR

Next you create an instance of an AWS Lambda using the AWS SAR. In the AWS Lambda console, click ‘Create function’ > ‘Serverless Application Repository’ and then search for the application named ‘alexa-skills-kit-nodejs-howtoskill’. This will create the AWS object instances needed to connect the AWS ecosystem with your Alexa skill (AWS Lambda, IAM Role, etc…)

— Name your application, click ‘Deploy’
— Wait until every instance status shows ‘Create_Complete’.
— Click on ‘View CloudFormation Stack’ & copy the generated Stack ID for later use.

Get HERE Location Services Developer Credentials

To get the required HERE application keys, you subscribe to the HERE Location Suite in the AWS Marketplace. Sign up and create a new project on this page in the AWS marketplace.

Use the AWS Marketplace to quickly integrate external vendor services into your AWS applications.

In the ‘JavaScript/REST’ section, click ‘Generate App ID and App Code’. Save your keys, you’ll need to add them to your AWS Lambda shortly.

Add HERE Location Services — Alexa Skill Lambda

AWS Lambda with an Alexa Skills trigger

Next you update the AWS Lambda code to add the HERE Location Services for use with the Alexa Skill. From the AWS Lambda console (example shown above), click on your Lambda to display the lambda code editor. First add your HERE credentials, obtained in the previous step.

You will then add code to perform a number of steps, these include the following:

  • Parse the intent to find the query (place category) and the location.
  • Make a request to the HERE Geocoder API to translate the location string into actionable coordinates to be able to use them in other services like routing, places, etc.
  • Get the coordinates and the query
  • Perform a places search to send the place of interest information
  • Get the results. The places search returns an array of results. The Alexa Skill presents information on the first result, including the name, distance, and address of the place.

Be sure to ‘Save’ the Lambda after you add the additional code sections. Make note the ARN of the Lambda (top right). For reference, the complete Lambda code is here.

Connect Lambda function to Alexa Skill and Test

In the last step, you connect your updated Lambda to your Alexa Skill. To do this navigate to the Alexa Developer console. Click on the ‘Endpoints’ button on the left sidebar of that console. Inside of the ‘Default Region’ field, paste your copied ARN AWS Lambda string value. The console is shown below.

Alexa Developer Console Endpoint View

Now you can test your skill directly in the Alexa Developer Console. To do so, click on the ‘Test’ button on the top menu area. To enable testing, click the switch that says ‘Test is disabled for this skill’. You are now able to test the skill by typing into the field or talking through your computer’s microphone.

Here’s a test script:
You: “Open HERE places”
Alexa: “Welcome to HERE Places. Trying searching for a place category and a location. For example, try “show me sushi in Seattle”
You: “Show me sushi in Seattle”
Alexa: “We found a nearby sushi place near Seattle! Sushi Kanpai is 0.3 miles away and is located at 900 8th Ave Seattle, WA 98104”

After you verify that your Alexa skill works as expected, you can optionally deploy it to a device — here’s a guide on how to do that.

What did we learn?

When working with new types of applications, (in this case voice-activated Alexa skills), using templates, tools and code examples can substantially speed up application development time.

Using the AWS Marketplace to locate partners, such as HERE Technologies, is often faster than going to vendor websites to explore using their 3rd party APIs in your AWS application.

Here are the tools in this tutorial:
1) Alexa Developer Portal — you used a code sample to create the required objects (invocations, intents and slots) and also to test your application
2) AWS Marketplace — you used the HERE Location Suite to quickly get required keys
3) AWS SAR — you used an Alexa application to quickly create AWS object instances so that your AWS application could interface with your Alexa skill

We also walk through the development of this sample in the short screencast below.

https://www.youtube.com/watch?v=KD30S2Q5tRM

Next steps

In the next installments we’ll be working with integrating HERE Technologies APIs with an even wider variety of AWS services. This will include additional types of voice-activated services (such as AWS Lex) and other.

For even more information about integration with Alexa, the HERE Technologies Evangelism team has published several blog posts on this topic.

1. Adding Alexa Voice Control to HERE Maps — link
2. Building an Alexa Skill with JavaScript and HERE Location Services — link
3. Geocode Addressing with Amazon Alexa, Golang, and the HERE Geocoder API — link

--

--