Alexa-skills-kit-sdk-for-nodejs: Access interaction model json?

Created on 17 Jul 2017  路  11Comments  路  Source: alexa/alexa-skills-kit-sdk-for-nodejs

Is there a way to access the JSON definition of the skill interaction model from the node sdk?

Most helpful comment

This doesn't help with the simulator not including "resolutions", but I wrote this helper method which I use to get the slot value (falling back to the raw value if "resolutions" is not present):

function slotValue(slot, useId){
    let value = slot.value;
    let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null;
    if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){
        let resolutionValue = resolution.values[0].value;
        value = resolutionValue.id && useId ? resolutionValue.id : resolutionValue.name;
    }
    return value;
}

You can call it like slotValue(this.event.request.intent.slots.SlotName) or slotValue(this.event.request.intent.slots.SlotName,true) if you want the id of the slot value to be returned instead of the text.

All 11 comments

Nope. The interaction model is about parsing user's input by alexa engine, then the request is generated for your skill. SDK is just for creating proper and valid JSON responses to requests. Nothing more.
Why do you want to access the skill interaction model? May be there is another option to do.

The reason is to resolve synonyms to the original slot value. I know you can do this from a nasty looking "resolutions" array that comes with the intent, but it is overly complicated, and also doesn't get sent from the test emulator. Being able to access the interaction model would let me look at the intent, then the slots, and find the value that matched the synonym, regardless of whether the test tool was used or not.

This doesn't help with the simulator not including "resolutions", but I wrote this helper method which I use to get the slot value (falling back to the raw value if "resolutions" is not present):

function slotValue(slot, useId){
    let value = slot.value;
    let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null;
    if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){
        let resolutionValue = resolution.values[0].value;
        value = resolutionValue.id && useId ? resolutionValue.id : resolutionValue.name;
    }
    return value;
}

You can call it like slotValue(this.event.request.intent.slots.SlotName) or slotValue(this.event.request.intent.slots.SlotName,true) if you want the id of the slot value to be returned instead of the text.

I'm going crazy I've seen @gadgetchnnel 's way a couple of times already but it doesnt seem to work for me.
The JSON never has a resolution request... am I missing something obvious? Or could someone direct me to a synonym/entity resolution tutorial for node.js?

Hi @shad00m
In order to receive entity resolution in your request, you need to define synonyms and IDs for slot values in the skill builder. See this documentation for more details.
Regards

I have defined IDs and synonyms for my slot type values, but regardless the ids are never sent in a resolutions array to my lambda function. What is going on here? Is there something else I have to do other than add IDs? They show up in my interaction model code, but not in the IntentRequest. Here is the intent request i get:

"request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.717c7447-ed8c-465d-b11e-378e8645e49f",
"intent": {
"name": "GetCoinPrice",
"slots": {
"Coin": {
"name": "Coin",
"value": "bitcoin"
}
}
},

I see no IDs in here

@GitKilla,

Here are a couple things you can check:

  1. make sure you are defining the synonyms using the Code Editor in Skill Builder (beta)
  2. make sure you can calling the correct intent that has resolution defined.

Regards

I am having the same issue in the US using alexa-sdk for Node. I'm not getting any IDs or Synonyms in my slots array, but I have defined synonyms and IDs for all my slot values in the Skill Builder Beta.

Here's an example of what I get from console.log(this.event.request.intent.slots):

{ Procedure: { name: 'Procedure', value: 'flushing' } }
"request": {
  "type": "IntentRequest",
  "requestId": "EdwRequestId.cecac590-1992-40a0-a1be-68edee54c123",
  "intent": {
    "name": "AssistantSelect",
    "slots": {
      "Procedure": {
        "name": "Procedure",
        "value": "flushing"
      }
    }
  },
  "locale": "en-US",
  "timestamp": "2018-01-29T00:09:39Z"
}

I tried for a while to find the synonyms or ID. Am I using an old version of the SDK or API that doesn't include entity resolution or something? Thanks.

Hi @DanLaufer,

Could you please post the language model json that's generated in the skill builder beta?

Thanks,
Tianren Zhang

@Amazon-tianrenz Sure. Here it is:

{
  "languageModel": {
    "types": [
      {
        "name": "Procedure",
        "values": [
          {
            "id": "line-flushing",
            "name": {
              "value": "Line Flushing",
              "synonyms": [
                "line flushing",
                "line-flushing",
                "line flush",
                "flush the line",
                "flushing",
                "flush line",
                "flush",
                "line"
              ]
            }
          },
          {
            "id": "test-blood-sugar",
            "name": {
              "value": "Blood Sugar Test",
              "synonyms": [
                "check blood sugar",
                "blood sugar",
                "test glucose",
                "blood glucose",
                "blood sugar test",
                "blood glucose test",
                "test blood glucose",
                "test blood sugar",
                "check blood glucose",
                "glucose",
                "sugar"
              ]
            }
          }
        ]
      }
    ],
    "intents": [
      {
        "name": "AMAZON.CancelIntent",
        "samples": []
      },
      {
        "name": "AMAZON.HelpIntent",
        "samples": []
      },
      {
        "name": "AMAZON.StopIntent",
        "samples": []
      },
      {
        "name": "MedAssistSelect",
        "samples": [
          "{Procedure}",
          "{Procedure} procedure"
        ],
        "slots": [
          {
            "name": "Procedure",
            "type": "Procedure"
          }
        ]
      },
      {
        "name": "GetCurrentStep",
        "samples": [
          "What",
          "repeat",
          "can you repeat that",
          "say that again",
          "what was that",
          "no",
          "i didn't",
          "not ready",
          "not done"
        ],
        "slots": []
      },
      {
        "name": "GetNextStep",
        "samples": [
          "Yes",
          "Ok",
          "Done",
          "Complete",
          "Finished",
          "Continue",
          "Forward",
          "Next",
          "Next Step",
          "go forward",
          "I did",
          "Indeed",
          "I think so",
          "I've done it",
          "alright"
        ],
        "slots": []
      },
      {
        "name": "GetPreviousStep",
        "samples": [
          "Last Step",
          "Backwards",
          "Previous",
          "Go Back",
          "Previous Step"
        ],
        "slots": []
      },
      {
        "name": "Menu",
        "samples": [
          "menu",
          "main menu",
          "return to menu",
          "back to menu"
        ],
        "slots": []
      },
      {
        "name": "Restart",
        "samples": [
          "Start Over",
          "Begin Again",
          "restart"
        ],
        "slots": []
      }
    ],
    "invocationName": "med assistant"
  }
}

Hi!

I have the same issue as DanLaufer.
this.event.request.intent.slots.MySlot.value will give me back the spoken word.
But how do I get the value or ID that I have entered for the slot type?

My language model looks similar to the one above.

Thanks, druelie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ancashoria picture ancashoria  路  6Comments

developer170883 picture developer170883  路  4Comments

rmtuckerphx picture rmtuckerphx  路  5Comments

kevinwu picture kevinwu  路  3Comments

rmtuckerphx picture rmtuckerphx  路  3Comments