I would like to ask, how to make the assistant give a different response based on if a slot is filled or not?
Here is a part of my configuration:
slots:
user:
type: text
influence_conversation: true
responses:
utter_greet:
- text: "Hey {user}! How can I help you?"
- text: "Hi, what can I do for you?"
I supposed that "influence_conversation" == true would define the behaviour of the assistant by choosing one over the other response depending on the existence of the slot. But, Sometimes I am getting a response like “Hey None! How can I help you?” which is not the desired behaviour.
Do I have to create a custom action to have the desired behaviour?
So my thought is something like the above:
-user input: "Hello, I am Vangelis"
-assistant's response:
if user_slot is filled then response:
"Hey Vangelis, how can I help you?"
elif user_slot is not filled then response:
"Hey, how can I help you?"
@EvanMath Hi, please cross-check this code and I have only given you the basic idea about how you can get the user name.
In domain.yml
intents:
- inform
slots:
user:
type: text
influence_conversation: true
entities:
- user
responses:
uttter_ask_name:
- text: " Please tell me you name"
utter_greet:
- text: "Hey {user}! How can I help you?"
- text: "Hi {user}, what can I do for you?"
actions:
- action_greet
In nlu.yml
- intent:inform
examples: |
- [Tom](user)
- [Lisa](user)
- It is [Tom](user)
- My name is [Bob](user)
Completely discard utter_greet and use action_greet instead. Keep your stories and everything the same as originally except for renaming the action.
Then, in the action, you check if the user has given his name and utter the according message.
class ActionGreet(Action):
def name(self):
return "action_greet"
def run(self, dispatcher, tracker, domain):
if (user := tracker.get_slot("user")):
dispatcher.utter_message(f"Hey {user}! How can I help you?")
else:
dispatcher.utter_message("Hi, what can I do for you?")
return []