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
질문됨 한 달 전229회 조회
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
답변함 한 달 전
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
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠