Chatbot rasa init conversation

Question:

I am starting with rasa and I want to make a chatbot that starts talking before the user, I attach an example:

Bot: Hello, how can I help you?
User: Hello, what time is it?
Bot: It's 5:23 p.m.

I know how to make the user write first but I don’t know how to do it the other way around. I have been looking for information and saw this link: https://forum.rasa.com/t/how-to-let-bot-start-the-conversation/20866/5 but it is still up to the user to write first

I’ve this:

stories.yml:

- story: greet
  steps:
  - action: action_utter_supply_greet_user
  - intention: greet
.... (continues)

actions.py:

class ActionGreetUser(Action):
    def name(self) -> Text:
        return "action_utter_supply_greet_user"
    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        dispatcher.utter_message("Hello! How can I help you?")
        return[UserUtternanceReverted()]

domain.yml:

actions:
  - action_utter_supply_greet_user

What’s wrong? How can I do it?

Thanks!

Asked By: Pau

||

Answers:

There is a dedicated section in the Rasa Docs about reaching out to the user which, I believe, you haven’t consulted yet (please, correct me if I’m wrong). Take a look and, if you encounter any issues, please, post on the Rasa forum.

Regarding your setup and why it doesn’t achieve what you want: Rasa stories describe what actions a bot should take in reaction to a user message and, if applicable, to previous conversation history. Rasa models "learn" from these stories how to react in context. When a story starts with a bot action, a model cannot learn from such a story because it’s unclear what the context is — after which user message should that action be predicted? And if you’re asking "How come it’s not clear? The story says that my action should start the conversation!", then it’s important to realise that a story doesn’t necessarily describe a conversation from the beginning — it can also represent just a part of a conversation, maybe just the ending. Again, if you have any follow-up questions, look at our docs and ask on the forum 🙂

Answered By: SamS

It would be great @Pau if you could share the config.py, elsewhere do check if your config.py is commented, within policies, uncomment the MemoizationPolicy. It is necessary for comparing and remembering the stories you mentioned.

Answered By: Fakhruddin Ezzey

Use the /execute rasa endpoint. Or, if you will connect your bot to messaging channel, then try to use those APIs.
Example to set up greeting message for Facebook Messenger channel:

from fbmessenger import BaseMessenger
from fbmessenger.thread_settings import GreetingText, GetStartedButton

APP_SECRET = os.environ['APP_SECRET']
PAGE_ACCESS_TOKEN = os.environ['PAGE_ACCESS_TOKEN']

messenger = BaseMessenger(page_access_token=PAGE_ACCESS_TOKEN, app_secret=APP_SECRET)
greeting_text = GreetingText('Hi! how can I help you?')
get_started = GetStartedButton(payload='/get_started')

Answered By: Zouhair Elhadi

We can init the conversation with bot by python SDK.

import requests

bot_message = "Hello, how can I help you?"
print(f"Bot: {bot_message}") # start conversation by bot
sender = "user"
while bot_message != "Bye":
    message = input("") # Get input from the user
    print(f"User: {message}")
    
    # Fetch Rasa Response. Before running this script make sure to start the rasa core and actions server by
    # "rasa shell" and "rasa run actions"
    # Also please consider the port, at the moment(26/Jan/2023)(RASA x3) the defualt port is http://localhost:5005/webhooks/rest/webhook
    # But may be it will change later
    r = requests.post('http://localhost:5005/webhooks/rest/webhook', json={"sender": sender, "message": message})
        
    bot_message = ""
    for i in r.json():
        bot_message += i['text']
    print(f"Bot: {bot_message}")
Answered By: nadhir hasan
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.