Kendall Weihe
Kendall Weihe

Reputation: 2075

Amazon AWS Lex slot type list

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": {}
}

Upvotes: 1

Views: 1078

Answers (1)

Dave Kerr
Dave Kerr

Reputation: 5297

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!

Upvotes: 1

Related Questions