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
preguntada hace un mes227 visualizaciones
2 Respuestas
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
EXPERTO
shibata
respondido hace un mes
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
respondido hace un mes

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas