How to capture slot value

0

I want to capture slot value within Lambda (JavaScript). My following code is not working:

const slotValue = event.slots.mySlot.value;

Note: This is not user input. I want slot value. I am working on Lex v2. While invoking hook (Lambda) from conditional branch I wish to set slot value, which should be fetched by Lambda.

Please suggest --Amarjit Singh Arora--

profile picture
asked 22 days ago216 views
2 Answers
0

Please share a little more background. Are you talking about Lex that you want to capture the slot value?

For a generic answer, once you have output the entire contents of an event, check its structure and the location of the expected value.

profile picture
EXPERT
shibata
answered 22 days ago
0

As mentioned above you need to get the slot object from the intent on the sessionState: event.sessionState.intent.slots.mySlot.value

However, this will get you the whole slot object which looks like this (in its most basic form):

{
    mySlot: {
        "shape": "Scalar",
        "value": {
            "originalValue": string,
            "interpretedValue": string,
            "resolvedValues": [
                string,
                ...
            ]
        }
    }
}

So to get the actual resolved string assigned to the slot you need to get the interpretedValue from the value object:

event.sessionState.intent.slots.mySlot.value.interpretedValue

The originalValue is the text from the utterance, the interpretedValue is the final resolved value, and the resolvedValues array is other options that the slot could resolve to. Check out the docs to see more about the Slot object https://docs.aws.amazon.com/lexv2/latest/dg/lambda-common-structures.html#lambda-slot (especially if you are using multi-value or composite, as the syntax to get the final value will differ).

You can see some example code here: https://github.com/aws-samples/amazon-lex-v2-lambda-integration-examples/blob/main/src/reminderBotLex2Lambda/intentHandlers/callIntentHandler.ts

AWS
Gillian
answered 16 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions