How to get a bot to give different answers for two different people

Hey @nik202

I have a situation:

My bot is going to talk to two different target audience:

1 - Doctors, and 2 - Non - doctors (or normal people.)

How do I build my bot that its able to answer the doctor with a more complex answer and the preson who is not a doctor with a simple answer?

Meaning there will be some way to choose if you are a doctor or not then get answered accordingly.

How can I do this?

When the bot first speaks, ask the user if they are a doctor or not using buttons:

responses:
  utter_ask_if_doctor:
  - text: "Are you a doctor?"
    buttons:
    - title: Yes
      payload: /inform{{"doctor": true}}
    - title: No
      payload: /inform{{"doctor": false}}

Also

  • Define the inform intent
  • Define the doctor slot
  • Set its type to bool and its auto-fill to true
    slots:
      doctor:
        type: bool
        auto_fill: true
    
  • Create appropriate stories and/or rules

There are other ways to achieve that and make it better. Look at forms.

1 Like

@atwine Check this demon use case for your reference and also you can follow Chris use case.

In domain.yml

intents:
 - doctor
 - non_doctor

responses:
 utter_menu:
    - text: For your consultation you can select from the below options:
      buttons:
        - title: Doctor Consultation
          payload: /doctor
        - title: Non-Doctor Consultation
          payload: /non_doctor

Create a story for the same or if you had written some action code for the same:

In stories.yml

For Doctor:

 - story: doctor consulation
    steps:
      - intent: doctor
      - action: action_doctor_consulation

For Non-Doctor:

 - story: non doctor consulation
    steps:
      - intent: non_doctor
      - action: action_non_doctor_consulation

OR

  - story: doctor
    steps:
      - intent: doctor
      - action: utter_doctor_consultation

  - story: non doctor
    steps:
      - intent: non_doctor
      - action: utter_non_doctor_consultation

Note: from above mention utterances you can mention any menu or question to be asked to user as shown in domain.yml

If you have any further doubts please, discuss and good luck!

@nik202

Thank you for that:

In my use case, i have faqs about a certain disease.

Am I right to say, I can set up the different faqs in two different yml files then later using rules I can choose which one gets answered?

Is that the right way of thinking?

Thank you, could you be having an already working solution, maybe a link to the code?

@atwine Yes, while using payload or custom action you can trigger the FAQs or any other question in two different buttons as shown

Thank you! Il do just that. Any sample project doing something like this? @nik202

@atwine These are the listed project on Rasa Github: https://github.com/RasaHQ/rasa/tree/main/examples Hope this will help you.

@atwine I am not sure, that you fetching data from FAQs or from Excel/CSV or doing manual, if you can share more then I will try to give suggestions on that.

@nik202 I am getting the faq from a yml file: faq.yml.

@atwine mean you manually doing that right? can you share faq.yml content?

intent: faq/what_is_hiv
examples: |
  - what's hiv
  - tell me about hiv
  - do you know about hiv

@nik202 that is what the faq yml contains just those intents.

@atwine are you using chitchat or FAQs using response selector?

@atwine

  - story: doctor
    steps:
      - intent: faq1
      - action: utter_doctor_consultation

  - story: non doctor
    steps:
      - intent: faq2
      - action: utter_non_doctor_consultation

You just need to mention the response in utter_doctor_consultation or utter_non_doctor_consultation

responses:
utter_doctor_consultation:
- text: "The Hive is the Human immunodeficiency virus infection and acquired immune deficiency syndrome"

utter_non_doctor_consultation:
-text: " faq2"

Note: I have just given you an idea, if you are using different intents, then for each intent you need to mention response in different utterances.

I hope it make sense to you now?

1 Like

I am using response selctor. I have both chitchat and faqs in different yml files. @nik202

@atwine For your reference please check this link:

and try to follow it. Good Luck!

Thank you, this helps.

Btw, how do I close a thread, I have been looking for the option…can’t seem to find it. @nik202

@atwine it should have show you on the post next to it which mention solution.

Just want to mention that Nik’s solution only remembers the user is a doctor for one step, while if you use slots, it will remember that for the whole session - then you can set the reply according to this anytime you want using custom actions.

Just know there are these two options depending on your use case. :slight_smile:

I think you are right thanks.

1 Like

Hello @ChrisRahme,

Please help me here, I am having this issue: my idea is this.

I have questions and answers for two types of people

Doctors:

  • the replies for these people are more complex

NotDoctors

  • the replies are simple and for normal people

I want to build the bot in such a way that it asks with two buttons, if you are a doctor then it shows the complex answers, if you are not a doctor, it shows simple faq answers.

This is how I have been trying to do below. Where could I be missing it.

when I run the bot I get the error below, its not picking the answers in the right way, it seems like its guessing or something.

Error:

Bot loaded. Type a message and press enter (use '/stop' to exit): 
Your input ->  hello                                                                                                                                     
Hello, how can I help you today?
? Hey! How are you? Are you a qualified Medical Personell?  1: Yes. (doctor{"doctor":true})                                                              
Your input ->  what is covid?                                                                                                                            
2021-09-24 17:34:24 ERROR    rasa.core.actions.action  - Couldn't create message for response 'utter_notdoctor/what_is_covid'.
Your input ->  how is it spread?                                                                                                                         
2021-09-24 17:34:33 ERROR    rasa.core.actions.action  - Couldn't create message for response 'utter_doctor/covid_spread'.
Your input ->   

Rasa Version

(rasaenv) Drs-MacBook-Pro:Trial-Ground drjamesmugume$ rasa --version
Rasa Version      :         2.8.1
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.1
Rasa X Version    :         0.39.3
Python Version    :         3.7.5
Operating System  :         Darwin-19.6.0-x86_64-i386-64bit
Python Path       :         /opt/anaconda3/envs/rasaenv/bin/python
(rasaenv) Drs-MacBook-Pro:Trial-Ground drjamesmugume$ 

NLU for Doctors

version: "2.0"
nlu:
- intent: doctor/what_is_covid
  examples: |
    - what is covid
    - what's corona
    - tell me about corona virus
    - corona?
    - covid-19?
    - define corona
    - what is covid19
- intent: doctor/covid_spread
  examples: |
    - how does it spread?
    - how does covid spread.
    - does it spread by air?
    - how can one contract it?
    - what means does it spread?
    - how do people get infected?
- intent: doctor/symptoms_covid
  examples: |
    - what are the symptoms?
    - symptoms of covid?
    - is temperature a symptom?
    - what are the signs of covid?
    - covid signs and symptoms
    - what should I look out for.
    - how do I know someone has covid?
- intent: doctor/covid_vaccine
  examples: |
    - what is the cure?
    - does it have a vaccine?
    - can it be vaccinated against?
    - what vaccine should I use for covid?

NLU for non doctors

version: "2.0"
nlu:
- intent: notdoctor/what_is_covid
  examples: |
    - what is covid
    - what's corona
    - tell me about corona virus
    - corona?
    - covid-19?
    - define corona
    - what is covid19
    - what is covid?
- intent: notdoctor/covid_spread
  examples: |
    - how does it spread?
    - how does covid spread.
    - does it spread by air?
    - how can one contract it?
    - what means does it spread?
    - how do people get infected?
- intent: notdoctor/symptoms_covid
  examples: |
    - what are the symptoms?
    - symptoms of covid?
    - is temperature a symptom?
    - what are the signs of covid?
    - covid signs and symptoms
    - what should I look out for.
    - how do I know someone has covid?
- intent: notdoctor/covid_vaccine
  examples: |
    - what is the cure?
    - does it have a vaccine?
    - can it be vaccinated against?
    - what vaccine should I use for covid?

Config

# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en

pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
    constrain_similarities: true
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
    constrain_similarities: true
  - name: ResponseSelector
    epochs: 100
    retrieval_intent: doctor
    constrain_similarities: true
  - name: ResponseSelector
    epochs: 100
    retrieval_intent: notdoctor 
    constrain_similarities: true
  - name: FallbackClassifier
    threshold: 0.35
    ambiguity_threshold: 0.1

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# No configuration for policies was provided. The following default policies were used to train your model.
# If you'd like to customize them, uncomment and adjust the policies.
# See https://rasa.com/docs/rasa/policies for more information.
  - name: MemoizationPolicy
  - name: RulePolicy
  - name: UnexpecTEDIntentPolicy
    max_history: 8
    epochs: 100
  - name: TEDPolicy
    max_history: 5
    epochs: 100
    constrain_similarities: true

Rules

version: "2.0"

rules:

- rule: Say goodbye anytime the user says goodbye
  steps:
  - intent: goodbye
  - action: utter_goodbye

- rule: Say 'I am a bot' anytime the user challenges
  steps:
  - intent: bot_challenge
  - action: utter_iamabot

- rule: ask doctor questions
  steps:
  - intent: doctor
  - action: utter_doctor

- rule: ask doctor questions
  steps:
  - intent: notdoctor
  - action: utter_notdoctor  

Domain:

version: '2.0'
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: false
intents:
- greet
- goodbye
- notdoctor:
    is_retrieval_intent: true
- doctor:
    is_retrieval_intent: true
- stop
- inform_doctor
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
entities:
- doctor
slots:
  doctor:
    type: bool
    influence_conversation: true
responses:
  utter_greet:
  - text: Hello, how can I help you today?
  utter_ask_if_doctor:
  - buttons:
    - payload: doctor{{"doctor":true}}
      title: Yes.
    - payload: notdoctor{{"doctor":false}}
      title: No.
    text: Hey! How are you? Are you a qualified Medical Personell?
  utter_cheer_up:
  - image: https://i.imgur.com/nGF1K8f.jpg
    text: 'Here is something to cheer you up:'
  utter_did_that_help:
  - text: Did that help you?
  utter_happy:
  - text: Great, carry on!
  utter_goodbye:
  - text: Bye
  utter_iamabot:
  - text: I am a bot, powered by Rasa.
  utter_doctor/what_is_covid:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: This is the answer for the doctors.
  utter_doctor/covid_spread:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: Covid_spred for doctors.
  utter_doctor/symptoms_covid:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: symptoms_covid for doctors.
  utter_doctor/covid_vaccine:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: covid_vaccine for doctors.
  utter_notdoctor/what_is_covid:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: This is the answer for the not_doctors.
  utter_notdoctor/covid_spread:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: Covid_spred for not_doctors.
  utter_notdoctor/symptoms_covid:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: symptoms_covid for not_doctors.
  utter_notdoctor/covid_vaccine:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: covid_vaccine for not_doctors.
actions:
- utter_ask_if_doctor
- utter_doctor
- utter_goodbye
- utter_greet
- utter_notdoctor

Stories

version: "2.0"
stories:
- story: doctor path
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - slot_was_set:
    - doctor: true
  - intent: doctor
  - action: utter_doctor 
  - intent: goodbye
  - action: utter_goodbye 

- story: not doctor path
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - slot_was_set:
    - doctor: false
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: goodbye
  - action: utter_goodbye

- story: interactive_story_1
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - intent: doctor
    entities:
    - doctor: true
  - slot_was_set:
    - doctor: true
  - action: utter_doctor
  - intent: doctor
  - action: utter_doctor
  - intent: goodbye
  - action: utter_goodbye

- story: interactive_story_1
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - intent: notdoctor
    entities:
    - doctor: false
  - slot_was_set:
    - doctor: false
  - action: utter_notdoctor
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: goodbye
  - action: utter_goodbye

Hello @nik202 ,

Please help me here, I am having this issue: my idea is this.

I have questions and answers for two types of people

Doctors:

  • the replies for these people are more complex

NotDoctors

  • the replies are simple and for normal people

I want to build the bot in such a way that it asks with two buttons, if you are a doctor then it shows the complex answers, if you are not a doctor, it shows simple faq answers.

This is how I have been trying to do below. Where could I be missing it.

when I run the bot I get the error below, its not picking the answers in the right way, it seems like its guessing or something.

Error:

Bot loaded. Type a message and press enter (use '/stop' to exit): 
Your input ->  hello                                                                                                                                     
Hello, how can I help you today?
? Hey! How are you? Are you a qualified Medical Personell?  1: Yes. (doctor{"doctor":true})                                                              
Your input ->  what is covid?                                                                                                                            
2021-09-24 17:34:24 ERROR    rasa.core.actions.action  - Couldn't create message for response 'utter_notdoctor/what_is_covid'.
Your input ->  how is it spread?                                                                                                                         
2021-09-24 17:34:33 ERROR    rasa.core.actions.action  - Couldn't create message for response 'utter_doctor/covid_spread'.
Your input ->   

Rasa Version

(rasaenv) Drs-MacBook-Pro:Trial-Ground drjamesmugume$ rasa --version
Rasa Version      :         2.8.1
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.1
Rasa X Version    :         0.39.3
Python Version    :         3.7.5
Operating System  :         Darwin-19.6.0-x86_64-i386-64bit
Python Path       :         /opt/anaconda3/envs/rasaenv/bin/python
(rasaenv) Drs-MacBook-Pro:Trial-Ground drjamesmugume$ 

NLU for Doctors

version: "2.0"
nlu:
- intent: doctor/what_is_covid
  examples: |
    - what is covid
    - what's corona
    - tell me about corona virus
    - corona?
    - covid-19?
    - define corona
    - what is covid19
- intent: doctor/covid_spread
  examples: |
    - how does it spread?
    - how does covid spread.
    - does it spread by air?
    - how can one contract it?
    - what means does it spread?
    - how do people get infected?
- intent: doctor/symptoms_covid
  examples: |
    - what are the symptoms?
    - symptoms of covid?
    - is temperature a symptom?
    - what are the signs of covid?
    - covid signs and symptoms
    - what should I look out for.
    - how do I know someone has covid?
- intent: doctor/covid_vaccine
  examples: |
    - what is the cure?
    - does it have a vaccine?
    - can it be vaccinated against?
    - what vaccine should I use for covid?

NLU for non doctors

version: "2.0"
nlu:
- intent: notdoctor/what_is_covid
  examples: |
    - what is covid
    - what's corona
    - tell me about corona virus
    - corona?
    - covid-19?
    - define corona
    - what is covid19
    - what is covid?
- intent: notdoctor/covid_spread
  examples: |
    - how does it spread?
    - how does covid spread.
    - does it spread by air?
    - how can one contract it?
    - what means does it spread?
    - how do people get infected?
- intent: notdoctor/symptoms_covid
  examples: |
    - what are the symptoms?
    - symptoms of covid?
    - is temperature a symptom?
    - what are the signs of covid?
    - covid signs and symptoms
    - what should I look out for.
    - how do I know someone has covid?
- intent: notdoctor/covid_vaccine
  examples: |
    - what is the cure?
    - does it have a vaccine?
    - can it be vaccinated against?
    - what vaccine should I use for covid?

Config

# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en

pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
    constrain_similarities: true
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
    constrain_similarities: true
  - name: ResponseSelector
    epochs: 100
    retrieval_intent: doctor
    constrain_similarities: true
  - name: ResponseSelector
    epochs: 100
    retrieval_intent: notdoctor 
    constrain_similarities: true
  - name: FallbackClassifier
    threshold: 0.35
    ambiguity_threshold: 0.1

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# No configuration for policies was provided. The following default policies were used to train your model.
# If you'd like to customize them, uncomment and adjust the policies.
# See https://rasa.com/docs/rasa/policies for more information.
  - name: MemoizationPolicy
  - name: RulePolicy
  - name: UnexpecTEDIntentPolicy
    max_history: 8
    epochs: 100
  - name: TEDPolicy
    max_history: 5
    epochs: 100
    constrain_similarities: true

Rules

version: "2.0"

rules:

- rule: Say goodbye anytime the user says goodbye
  steps:
  - intent: goodbye
  - action: utter_goodbye

- rule: Say 'I am a bot' anytime the user challenges
  steps:
  - intent: bot_challenge
  - action: utter_iamabot

- rule: ask doctor questions
  steps:
  - intent: doctor
  - action: utter_doctor

- rule: ask doctor questions
  steps:
  - intent: notdoctor
  - action: utter_notdoctor  

Domain:

version: '2.0'
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: false
intents:
- greet
- goodbye
- notdoctor:
    is_retrieval_intent: true
- doctor:
    is_retrieval_intent: true
- stop
- inform_doctor
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
entities:
- doctor
slots:
  doctor:
    type: bool
    influence_conversation: true
responses:
  utter_greet:
  - text: Hello, how can I help you today?
  utter_ask_if_doctor:
  - buttons:
    - payload: doctor{{"doctor":true}}
      title: Yes.
    - payload: notdoctor{{"doctor":false}}
      title: No.
    text: Hey! How are you? Are you a qualified Medical Personell?
  utter_cheer_up:
  - image: https://i.imgur.com/nGF1K8f.jpg
    text: 'Here is something to cheer you up:'
  utter_did_that_help:
  - text: Did that help you?
  utter_happy:
  - text: Great, carry on!
  utter_goodbye:
  - text: Bye
  utter_iamabot:
  - text: I am a bot, powered by Rasa.
  utter_doctor/what_is_covid:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: This is the answer for the doctors.
  utter_doctor/covid_spread:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: Covid_spred for doctors.
  utter_doctor/symptoms_covid:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: symptoms_covid for doctors.
  utter_doctor/covid_vaccine:
  - condition:
    - type: slot
      name: doctor
      value: true
    text: covid_vaccine for doctors.
  utter_notdoctor/what_is_covid:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: This is the answer for the not_doctors.
  utter_notdoctor/covid_spread:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: Covid_spred for not_doctors.
  utter_notdoctor/symptoms_covid:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: symptoms_covid for not_doctors.
  utter_notdoctor/covid_vaccine:
  - condition:
    - type: slot
      name: doctor
      value: false
    text: covid_vaccine for not_doctors.
actions:
- utter_ask_if_doctor
- utter_doctor
- utter_goodbye
- utter_greet
- utter_notdoctor

Stories

version: "2.0"
stories:
- story: doctor path
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - slot_was_set:
    - doctor: true
  - intent: doctor
  - action: utter_doctor 
  - intent: goodbye
  - action: utter_goodbye 

- story: not doctor path
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - slot_was_set:
    - doctor: false
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: goodbye
  - action: utter_goodbye

- story: interactive_story_1
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - intent: doctor
    entities:
    - doctor: true
  - slot_was_set:
    - doctor: true
  - action: utter_doctor
  - intent: doctor
  - action: utter_doctor
  - intent: goodbye
  - action: utter_goodbye

- story: interactive_story_1
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_ask_if_doctor
  - intent: notdoctor
    entities:
    - doctor: false
  - slot_was_set:
    - doctor: false
  - action: utter_notdoctor
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: notdoctor
  - action: utter_notdoctor
  - intent: goodbye
  - action: utter_goodbye