Learn
Use Synonyms in Lambda Functions
Parse JSON

In the previous exercise you saw that Option 2 (using Entity Resolution) is faster and easier to maintain. Where can you access these synonyms? In the JSON request.

About JSON Request

When users interact with your skill, Alexa sends off a JSON request to your AWS Lambda function that looks something like the text file — request.js shown on the right. If your skill uses entity resolution, the JSON request includes some additional important information, including the synonym Alexa heard, the status code of the resolution, and the resolved value.

In Node, we can access the synonym using:

this.event.request.intent.slots.YOUR_SLOT_NAME.value

Where YOUR_SLOT_NAME is the desired slot.

We can access the status code using:

this.event.request.intent.slots.YOUR_SLOT_NAME.resolutions.resolutionsPerAuthority[0].status.code

We can access the resolved value using:

this.event.request.intent.slots.YOUR_SLOT_NAME.resolutions.resolutionsPerAuthority[0].values[0].value.name

Instructions

1.

Let’s do a little bit of practice with a sample JSON request.

Because this is a reserved word in JavaScript, we’ve setup main.js so you can omit this, and start with event.

Using console.log(), print the synonym in the JSON request.

2.

Using console.log(), print the status code in the JSON request.

3.

Using console.log(), print the resolved value in the JSON request.

Folder Icon

Take this course for free

Already have an account?