How to ask the user's name and use it back in the conversation

Hi , i want that the bot ask for user name and than use it back to greet ,

User: hi

Bot : hi, what’s ur name?

user : my name is Ali

Bot : hi ali how can i help you?

The name entered by the user (ali) is unknown for the model . how can i do it ,?

Nlu.md

intent:greet

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

intent:goodbye

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

intent:ask_name_action

Domain.yml

intents:

  • greet
  • goodbye
  • ask_name_action entities:
  • name slots: name: type: text actions:
  • action_hello_world
  • utter_greet
  • utter_goodbye

responses: utter_greet:

  • text: "Hey! please enter your name "

utter_goodbye:

  • text: “Bye”

session_config: session_expiration_time: 60 carry_over_slots_to_new_session: true

stories.md

ask_name

  • greet
    • utter_greet
  • ask_name_action
    • action_hello_world
  • goodbye
    • utter_goodbye

Actions.py

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker

from rasa_sdk.executor import CollectingDispatcher

class ActionHelloWorld(Action):

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

 def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
     name= tracker.get_slot("name")
     msg="hello {} how can i help you?".format(name)
     dispatcher.utter_message(text=msg)

     return []

Please Refer Documentation you will find it or go through

https://github.com/bparikh99/rasa_nlu/blob/master/actions.py

Thank you Mr Bhavya,

But what i meant is that i want the bot to answer the user bye this querry :

-hi user_name

even if i didn’t mention the name of the user the training set … the bot should be able to respond

Hi, @hamzaghannem2 I would recommend taking a look this blog post it covers generalizing entity recognition including names.

1 Like

thank you Oli, Do you think it is feasible in rasa , ?

Absolutely, I would recommend following the flow chart. In worst case you would need to provide a couple hundred examples for training. Best case spacy does it without you doing much work at all.