How to create a chatbot which asks name, email, and message

https://ridingsolo.in/

In the above site, they have a chatbot asking for name, email, and message. I want to create one for my company, can someone give me a source code or someone did like that online. Thank you!!

Hi @reddyakilesh22, I’ve seen that page has a form that allows users to input their data, assuming you want to achieve the same thing but using a rasa powered bot instead (which is an awesome idea btw), you would have to use rasa Forms (find the official info here )

Summary

Assuming you already know how to use rasa, you will need to declare 3 entities on your domain.yml file like this:

entities:
- client_name
- client_email
- client_message

then would have to declare the slots types for this 3 entities you just declared above, like this :

slots:
  client_name:
    type: text
  client_email:
    type: text
  name:
    type: text
  client_message:
    type: text

then you would have to the responses which are just the questions your assistant will ask to the users, keep in mind that they have to start with utter_ask_. so your assistant knows it is a question he must ask to the user, like this :

       responses:
          utter_ask_client_name:
          - text: What is your email address ?    
          utter_ask_client_email:
          - text: What is your email address ?
          utter_ask_client_message:
          - text: what is the message you would like me to send to our team ?

Finally, you just have to the declare the form you will use on your actions.py file, like this:

forms:
- form_get_client_message

Now on your action.py file create a required slots function so it will loop the user till he/she writes the info you need, like this:

class ActionUserMessage(FormAction):

    def name(self) -> Text:
        return "form_get_client_message"

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        """A list of required slots that the form has to fill."""
         
        return ["client_name", "client_email", "client_message"]

    def submit(self,dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any],):

        # Do something dramatically here, like call an API for example lol

        return []

Now on your stories.md file, assuming that the intent send_message is when the user say for example I would like to leave a message,

put something like this

## Get Info from user:
 * send_message
   - form_get_client_message
   - form{"name": "form_get_client_message"}
   - form{"name": null}
  - utter_good_bye

It will activate the form, loop till it is done and deactivate it

I think the full code would be something like this :slightly_smiling_face:

Domain.yml

entities:
- client_name
- client_email
- client_message
slots:
  client_name:
    type: text
  client_email:
    type: text
  name:
    type: text
  client_message:
    type: text
responses:
  utter_ask_client_name:
  - text: What is your email address ?    
  utter_ask_client_email:
  - text: What is your email address ?
  utter_ask_client_message:
  - text: what is the message you would like me to send to our team ?
forms:
- form_get_client_message

Actions.py

class ActionUserMessage(FormAction):

    def name(self) -> Text:
        return "form_get_client_message"

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        """A list of required slots that the form has to fill."""
         
        return ["client_name", "client_email", "client_message"]

    def submit(self,dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any],):

        # Do something dramatically here, like call an API for example lol

        return []

Storied.md

## Get Info from user:
 * send_message
   - form_get_client_message
   - form{"name": "form_get_client_message"}
   - form{"name": null}
  - utter_good_bye

Hope it helps :slightly_smiling_face:

1 Like

Thank you!! But in intents say I gave

When I give other names say Justin it’s showing me Failed to extract slot client_name with action form_get_client_message, do you have a solution for that?

I have seen somewhere that I need to use spacy pipeline and others so that my bot understands. But still I was facing the same problem but I kinda feel I didn’t give my config.yml correctly so can you try and let me know what all should be given inside config.yml. Thank you!!

Hey @reddyakilesh22,

Add form policy on your policies in config.yml

Add intents to your domain file like (client_name_entry, client_email_entry, etc etc)

Specify how the data might be given on your NLU file for each intent

Summary

Domain.yml

Add intents to your domain file like (client_name_entry, client_email_entry, etc etc)

intents:
- client_name_entry
- client_email_entry
- client_message_entry

config.yml

Add form policy on your policies in config.yml file like this :

language: en
pipeline: supervised_embeddings
policies: 
  - name: FormPolicy

nlu.md

On your nlu file specify how the data might be given like this:

## intent:name_entry
- My name is [Rohit Sharma] (client_name)
- [John Doe] (client_name)
- I am [Vishnu] (client_name)
- [Peter Richard] (client_name)
- People call me [Priya] (client_name)
- [Jane Doe] (client_name)
- [Max Mustermann] (client_name)
- You can call me [Supriya] (client_name)

do this for every intent with their respective entities name

Let me know if it works

Hey, I have done everything like you said. I’m still getting same error.

Your input -> hi
Hey! How can I help you? Your input -> Sales
What is your name ? Your input -> Divya
2020-09-16 20:14:21 ERROR rasa.core.actions.action - Failed to extract slot client_name with action form_get_client_message Hey! How can I help you? Your input -> Sales
Your input -> hi
Hey! How can I help you? Your input -> Sales
What is your name ? Your input -> Jonathan
c:\users\reddy\anaconda3\envs\bot\lib\site-packages\rasa\utils\common.py:363: UserWarning: Action ‘form_get_client_message’ set a slot type ‘client_name’ which it never set during the training. This can throw off the prediction. Make sure to include training examples in your stories for the different types of slots this action can return. Remember: you need to set the slots manually in the stories by adding ‘- slot{“client_name”: Jonathan}’ after the action. What is your email address ? Your input ->

You can see when I gave name saying Divya it shows error and then when I say Jonathan it goes to next step asking email.

nlu.md

intent:greet

  • hey
  • hello
  • hi
  • good morning
  • good evening
  • hey there

intent:goodbye

  • bye
  • goodbye
  • see you around
  • see you later

intent:affirm

  • yes
  • indeed
  • of course
  • that sounds good
  • correct

intent:deny

  • no
  • never
  • I don’t think so
  • don’t like that
  • no way
  • not really

intent:bot_challenge

  • are you a bot?
  • are you a human?
  • am I talking to a bot?
  • am I talking to a human?
  • what is your name?

intent:send_message

  • Sales

intent:client_email_entry

intent:client_name_entry

The highlighted ones are entities with client_name and client_email

domain.yml

session_config: session_expiration_time: 60 carry_over_slots_to_new_session: true

intents:

  • greet
  • goodbye
  • affirm
  • deny
  • client_name_entry
  • client_email_entry
  • client_message_entry
  • bot_challenge
  • send_message

entities:

  • client_name
  • client_email
  • client_message

slots:

client_name:

type: text

client_email: type: text

client_message: type: text

responses:

utter_greet: - text: Hey! How can I help you?

utter_goodbye: - text: Bye

utter_iamabot: - text: I am a bot, powered by Rasa

utter_ask_client_name: - text: What is your name ?

utter_ask_client_email: - text: What is your email address ?

utter_ask_client_message: - text: what is the message you would like me to send to our team ?

forms:

  • form_get_client_message

config.yml

Configuration for Rasa NLU.

Components

language: en pipeline: supervised_embeddings

Configuration for Rasa Core.

Policies

policies:

  • name: MemoizationPolicy
  • name: TEDPolicy max_history: 5 epochs: 100
  • name: MappingPolicy
  • name: FormPolicy

stories.md

happy path

  • greet
    • utter_greet
  • goodbye
    • utter_goodbye

say goodbye

  • goodbye
    • utter_goodbye

bot challenge

  • bot_challenge
    • utter_iamabot

Get Info from user:

  • send_message
    • form_get_client_message
    • form{“name”: “form_get_client_message”}
    • form{“name”: null}
    • utter_goodbye

Did you specify the slot client_name on your NLU ?

e.g:

## intent:name_entry
- My name is [Rohit Sharma] (client_name)
- [John Doe] (client_name)
- I am [Vishnu] (client_name)
- [Peter Richard] (client_name)
- People call me [Priya] (client_name)
- [Jane Doe] (client_name)
- [Max Mustermann] (client_name)
- You can call me [Supriya] (client_name)

Yes

I just replicated it now, and it seems to work fine, do you mind sharing some screenshots please, in case I forgot some steps

@Tanja can you please look into this, Eden has helped me out with this problem and actually made it and put it up online on his GitHub profile GitHub - jusce17/rasa_form_example and I have done the same thing as he did and downloaded the same packages as his but still, I’m unable to solve my issue, like if I give a name which isn’t in my nlu.md file it’s giving me an error. Like this:

ERROR rasa.core.actions.action - Failed to extract slot client_name with action form_get_client_message