Jeet Bardapurkar
Jeet Bardapurkar

Reputation: 3

How do I use Amazon Lex v2's inputTranscript to allow for a wide open slot in lambda code?

I have read all the other answers related to this topic but since I'm a complete beginner to lex, they're all too vague for me. The official documentation doesn't contain any details about how to implement this either. I need a concrete example in the form of a complete lambda code which allows me to take any input the user enters in a slot amazon lex v2.

So, basically what I have is a bot with a single intent which contains, say 3 slots - name, description and priority. The name obviously contains the name and will use Lex's inbuilt name slot type, the priority will be just a number between 1 to 5 which is also easily implemented in lex. The description is a string of text which user enters and I cannot for the life of me figure out how to implement this. I know I'm supposed to use inputTranscript but I have no idea what that looks like in a real lambda code which would work for a bot like mine. If someone can show that to me, or at the very least provide very detailed instructions, I would be grateful.

Thank You.

Upvotes: 0

Views: 1176

Answers (2)

Bela Vizy
Bela Vizy

Reputation: 1164

The inputTranscript attribute is the raw input in the lambda payload. You have to parse out the free text part (description) yourself.

Your utterance probably looks something like this: {name} {description} {priority}

There is no "free text" slot type in LEX or any other NLU I know. Those descriptions have to be broken down to more slots. Otherwise you have to roll your own "NLU" - that is parse the raw input to dig out description. For example if you have the name and priority slots, then the description is everything between these two. I'm just guessing. This is why there is no ready made fulfillment lambda for this.

Did this help? If not let me know.

Upvotes: 0

Reegz
Reegz

Reputation: 579

The Lex documentation is fairly good at explaining how you can use a Lambda function to validate input.

Using Lambda you can intercept the user's input and save it as the final value. To do this you will need to take a look at the input into your Lambda function to understand where to look for the specific pieces of data that you're after.

On a high level, you need to traverse through the slotDetails on the currentIntent to find the original value for the description slot.

originalValue = intent_request['currentIntent']['slotDetails']['description']['originalValue']

Once you've grabbed this value you will need to set it on the slots array that's returned to Lex.

slot_values["description"] = originalValue

There's sample code available in the Lex documentation to assist you with building the correctly formatted response.

AWS Lex Lambda Input Event and Response Format

Upvotes: 0

Related Questions