0
votes

thank you for your help in advance! I have an intent and a custom slot value for this intent, the slot value is called "event" which is a value from my "LIST_OF_EVENTS" list.

In this list, I have many options for slots, but more importantly, I have many synonyms for each slot value. To treat them all the same, I would like to use the ID I have assigned to each slot. I set them as 0-11. Now getting this ID is important because based on this id defines what part of a JSON file I am giving back to the user.

The problem here is that I cannot figure out how to get this ID in my code, I have done a lot of research and looked through lots of documentation yet I still can't manage to get the ID.

I have tried:

var id = alexa.event.request.intent.slots.event.resolutions.resolutionsPerAuthority[].values[].value.id;

as well as many other things.

When I look at the intent request send via the testing platform amazon provides I cannot seem to find this resolutions object in my intent request. There is nothing like this. However, in their documentation, on multiple pages, it shows and refers to this object. Here is the link to the documentation.

My request that amazon creates is

{
  "session": {
    "new": false,
    "sessionId": "SessionId.4bce2f23-d11e-4022-b6d1-b91aec14b9d6",
    "application": {
      "applicationId": "amzn1.ask.skill.e0cc33bb-4ad7-4bbb-91e8-a0eab852a49c"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.AF53KNANELPR77LPYI7GAED6MM2EIVTFZZRJQ3FGLKW7HMRWLEEET6T7MEY5FLD67JO4OZNTTRFB2XDH6J2X2GGHZKOM4UDW6WKP6GLCYW3OI7WCHW2HTEYNQQWUF6TARFBX64WUIAAUL6RFCZ663P4RKGJ43PEXQ43G4BSA3KWSKKRUPCXJWFLWUSDAHD6LMAQKXCPREDMKHQI"
}
  },
  "request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.0171880d-8006-47d9-b17b-52e1f431f5f4",
"intent": {
  "name": "WhenIsBLANK",
  "slots": {
    "event": {
      "name": "event",
      "value": "dream to fly"
    }
  }
},
"locale": "en-US",
"timestamp": "2017-10-14T20:24:43Z"
  },
  "context": {
"AudioPlayer": {
  "playerActivity": "IDLE"
},
"System": {
  "application": {
    "applicationId": "amzn1.ask.skill.e0cc33bb-4ad7-4bbb-91e8-a0eab852a49c"
  },
  "user": {
    "userId": "amzn1.ask.account.AF53KNANELPR77LPYI7GAED6MM2EIVTFZZRJQ3FGLKW7HMRWLEEET6T7MEY5FLD67JO4OZNTTRFB2XDH6J2X2GGHZKOM4UDW6WKP6GLCYW3OI7WCHW2HTEYNQQWUF6TARFBX64WUIAAUL6RFCZ663P4RKGJ43PEXQ43G4BSA3KWSKKRUPCXJWFLWUSDAHD6LMAQKXCPREDMKHQI"
  },
  "device": {
    "supportedInterfaces": {}
  }
}
  },
  "version": "1.0"
}

Please let me know if anyone has any ideas on how to solve this issue, thank you!

1

1 Answers

0
votes

The slot data sent to your lambda will be a string, for example "dream to fly" as shown in the request you posted.

It will be up to your lambda code to compare this string with your LIST_OF_EVENTS values to determine which one was sent. This is typically done by iterating through an array of strings containing expected values, but might also be done using a switch statement with cases for each possible value. Remember to handle unmatched values, because sometimes what you get in the slot value is not what you expect.

You can then use that index to select what your response will be.

For example:

var slot = request.intent.slot.event.value;
var index;
for(index=0; index<NUM_SLOT_VALUES; index++) {
    if(knownValues[i] == slot) {
        break;
    }
}
// index is now the index of the matching value, or NUM_SLOT_VALUES if not found

You can find lots of information online about performing loops in javascript, such as this link.