내용으로 건너뛰기

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?

질문됨 일 년 전394회 조회
1개 답변
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”.

전문가
답변함 일 년 전
  • 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.

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

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

관련 콘텐츠