3
votes

I'm building a chatbot that allows users to pick one or more services. What I want is the user to add many slots of the same type in one utterance.

My Service slot has services like:

  • Counseling
  • Therapy
  • Healthcare
  • Addiction treatment...

I want the user to be able to type this:

I need {Service} and {Service}
I need {Service}, {Service} and {Service}

e.g. I need counseling and therapy

But when I try to build with those utterances I get this error:

The slot "{Service}," is invalid in utterance "I need {Service}, {Service} and {Service}" for intent "FindService". Slots in an utterance must have the form {slotName}.

1

1 Answers

4
votes

I was able to recreate your error:

The slot "{_____}," is invalid in utterance "__________" for intent "___". Slots in an utterance must have the form {slotName}.

This is caused by having any character next to the curly braces, and Lex needs spaces on both sides of the "{slotName}". You will have to remove the comma entirely because if you simply fix that by putting a space between the } and , then you will get this error:

"," in utterance "________" for intent "___" contains an unsupported character or word. An utterance can consist only of Unicode characters, spaces, and valid punctuation marks. Valid punctuation marks are: periods for abbreviations, underscores, apostrophes, and hyphens. If there is a slot placeholder in your utterance, ensure that it's in the {slotName} format and has spaces at both ends.

Also, after you remove the comma, you should still receive another error:

The slot name "Service" was used more than once in utterance "I need {Service} {Service} and {Service}" for intent "FindService".

So to fix that, you should create multiple slots with different slotNames but all using the same slotType. Use slot names like: Service_one Service_two Service_three. Note that you cannot use digits (0-9) in slot names or you will get error:

The value specified for 'slots.#.member.name' is invalid. Member must satisfy regular expression pattern: ^(A-Za-z?)+$

After creating those 3 separate slots, you can write your new valid utterance like this:

I need {Service_one} and {Service_two}
I need {Service_one} {Service_two} and {Service_three}

No errors with that set up. Now I don't know how well Lex will differentiate the list of utterance #2, especially having the two slots right next to each other and looking for the same slotType values. So you will have to test that out and watch how Lex fills the slots, then build your Lambda validation code accordingly.