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
已提问 1 个月前227 查看次数
2 回答
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
专家
shibata
已回答 1 个月前
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
已回答 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则