1
votes

This is a pretty simple question, but I can't find any evidence for an answer. I want to configure a slot type to me a list -- meaning that Lex will have to continue asking more elements in that list.

For example, here is what a back-and-forth should look like:

Lex: What flowers would you like to order?
Me: roses
Lex: Any other types?
Me: yes, I also want lillies
Lex: Anything else?
Me: that is all

An example payload that gets sent to a Lambda looks like this:

{
  "currentIntent": {
    "slots": {
      "PickupDate": "2030-11-08",
      "PickupTime": "10:00",
      "FlowerType": "lilies"
    },
    "name": "OrderFlowers",
    "confirmationStatus": "None"
  },
  "bot": {
    "alias": "$LATEST",
    "version": "$LATEST",
    "name": "OrderFlowers"
  },
  "userId": "John",
  "invocationSource": "DialogCodeHook",
  "outputDialogMode": "Text",
  "messageVersion": "1.0",
  "sessionAttributes": {}
}

That ^^^ was taken directly from the examples Test Configurations in AWS Lambda console.

I want it to look like this:

{
  "currentIntent": {
    "slots": {
      "PickupDate": "2030-11-08",
      "PickupTime": "10:00",
      "FlowerTypes": [
             "roses",     
             "lilies"
       ]    
},
    "name": "OrderFlowers",
    "confirmationStatus": "None"
  },
  "bot": {
    "alias": "$LATEST",
    "version": "$LATEST",
    "name": "OrderFlowers"
  },
  "userId": "John",
  "invocationSource": "DialogCodeHook",
  "outputDialogMode": "Text",
  "messageVersion": "1.0",
  "sessionAttributes": {}
}
1
According to docs.aws.amazon.com/lex/latest/dg/API_Slot.html is looks like a slot is always a string. Could you accomplish what you are trying to accomplish by adding additional slots? e.g. FlowerType01, FlowerType02, ... FlowerType99?Justin Heath
I could, but I'm hoping there is a better wayKendall Weihe
You could create a validation hook and utilize the elicit slot call to populate your own array of flowers, which can be stored as a sessionAttribute. This is messy and you are probably better off using multiple slots as mentioned above.Milk

1 Answers

1
votes

Lex slots are always strings, so you will have to come up with a more sophisticated solution. I would suggest:

  1. Create an intent asking what flowers to order. You should be eliciting a slot called 'flower'.
  2. When you run your code, take the input from the slot, and add it to a session attribute. Now ask a follow up question "Enter any more flowers you'd like to order, or 'done' if you are finished"
  3. Elicit the slot again.
  4. Every time you check the slot (before adding it to the session), see if it matches 'done'. If it does, you can fulfil the order and then the event.

Goofy, I know, but Lex has very limited options for slots right now!