Ir para o conteúdo

In Lex v2, how do I reference a subSlot to use it in dialogue or conditions?

0

Take an example of a composite slot type fullName with firstName and lastName using the correct built-in slot types. I can collect this information easily, but how do I use it? If I want to say "thanks, John" instead of "thanks, John Doe," how do I do so?

I'm less interested in workarounds for this example (such as making the subSlots each individual slots) and more interested in if there's currently an elegant way to do this.

Another example is based on the following: https://docs.aws.amazon.com/lexv2/latest/dg/composite-slots.html

If I have collected that a car is a 2021 White Toyota Camry, can I run a conditional on the year so older cars are given different outcomes than newer cars? Can I say "We'll take great care of your Camry" by referencing the subSlot?

feita há um ano394 visualizações
1 Resposta
0

In Amazon Lex, you can use composite slot types to collect multiple pieces of information within a single slot.

For a fullName slot with firstName and lastName subslots, you can reference these subslots individually in your responses or in your code. For example, you can use sessionAttributes.fullName.firstName to say “Thanks, John” instead of “Thanks, John Doe”.

If you have collected car details using a composite slot type, you can run conditionals on the subslots. For example, you can check sessionAttributes.car.year to give different responses for older and newer cars. You can also reference the model subslot as sessionAttributes.car.model to say “We’ll take great care of your Camry”.

ESPECIALISTA
respondido há um ano
  • Based on your comment, it sounds like this is simple in a repo-driven Lex bot. How exactly would I do this if I built my bot in the web interface? I'm a JS engineer, but I've only built bots in the web interface because some of my team members aren't.

    I also didn't understand the use of a Session Attribute. Does your method not work for slots? Do I first need to save the slot data to a session attribute? I've tried adding {user.firstName} to my response text and to conditionals, where user is the slot name of type fullName. It failed as invalid. Please advise.

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.