Chatroom let the bot start the conversation?

I am using chatroom platform for the RASA bot. Although it can set a welcome message to the user, the user still has to say something like “hi” to start the conversation.

I am wondering if there is a way for the bot start the conversation instead?

1 Like

anyone knows?

Hi! We have a rasa chatbot on a web page using chatroom too, and have the same problem. did you solve it? I’ve found this chatroom/index.html at master · scalableminds/chatroom · GitHub I’m not sure if putting the text (and if possible buttons) in the welcomeMessage it would appear first in the conversation thanks for helping!

You should set up the chat room to automatically send the ‘hello’ intent (or however you’re calling your greet intent) once the chatroom activates.

The rasa-webchat component from mrbot-ai allows you to specify the initial intent payload to send to your bot. The example in the readme page show it set as follows…

initPayload: "/get_started",

@e8180kimo did you got answer

except intent can i use template from domain.yml

You need to send /session_start as the initial payload for your custom chat channel, then you can hook into the default action_session_start. You can then enter a dispatcher.utter_message() in the run function to send a message to the user “proactively”.

Hey @niveK ,

I tried this on telegram , but dosn’t work.

Do you have a working example for this? Below is my actions.py file. I have added the class ActionSessionStart. I have also included - action_session_start in my domain.yml

from typing import Any, Text, Dict, List
    from rasa_sdk import Action, Tracker
    from rasa_sdk.executor import CollectingDispatcher
    from rasa_sdk.forms import FormAction
    from rasa_sdk.events import SlotSet, SessionStarted, ActionExecuted, EventType



class ActionSessionStart(Action):
def name(self) -> Text:
    return "action_session_start"  # This name function returns the name of the custom action.Here is is action_session_start

@staticmethod
def fetch_slots(tracker: Tracker) -> List[EventType]:
    """Collect slots that contain the user's name and phone number."""

    slots = []

    for key in ("name", "email", "pincode", "mobnumber"):
        value = tracker.get_slot(key)
        if value is not None:  # this is how to check if slot value is filled or not.
            slots.append(SlotSet(key=key, value=value))

    return slots

def apply_to(self, tracker: "DialogueStateTracker") -> None:
    # noinspection PyProtectedMember
    tracker._reset()
    
async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> List[EventType]:

    # the session should begin with a `session_started` event
    events = [SessionStarted()]
    #
    # # any slots that should be carried over should come after the
    # # `session_started` event
    # events.extend(self.fetch_slots(tracker))
    #
    # # an `action_listen` should be added at the end as a user message follows
    dispatcher.utter_message(template="utter_greet_ask")
    events.append(ActionExecuted("action_listen"))
    #

    return events

But Still it dosn’t seem to start the conversation with utter_ask_greet

I ran the command rasa run actions -p 5002 in one terminal and rasa run in another. Using ngrok to connect to telegram. All telegram configutations are done and set up the bot in telegram as well.

Here are my logs…

I can’t seem to figure it out…Could you please help :slight_smile:?

I don’t think it’s possible on telegram to have the bot start the conversation, but I did notice that in your run action you’re using utter_greet_ask instead of utter_ask_greet in the ActionSessionStart.run() like you mentioned.

Also, I’m not sure if it was because of the way it pasted the python code in your comment, but it looks like you have some indenting issues in the class, which might be why it’s not finding the action by name.

Hey @niveK ,

The indentaion in the class file is proper , I have verified …like you said it was because of the pasting issues :sweat_smile: in the comment.

Here is my github repo:

Could you have a look ??

So, for telegram starting a convo by bot is out of the question :thinking:??

Alright, so for the action_session_start not triggering, it was because you needed to retrain a new model after overriding the default action_session_start. Everything else with action_session_start looked good fine

As for the Telegram question it seems others have mentioned this as part of the functionality – I haven’t used Telegram all that much, so I can’t say for sure, but from a quick search around, telegram might send /start? If that’s the case, you have to add this to your domain.yml's intents:

- start:
    triggers: action_session_start

as well as a matching story:

## telegram sends start message (mapped action)
* start
    - action_session_start

Take that with a grain of salt, though, I’m not 100% sure that’s how Telegram handles it, so YMMV.

1 Like

Hey @niveK ,

Thanks a bunch man, it worked.

You can’t make a bot initiate a convo in telegram, has to start with a /start sent by the user.

So I just added the below to my domain.yml.

- start:
    triggers: utter_bot_function

I tried removing the whole ActionSessionStart class and have the default action_session_start and it works the way I want. That’s a workaround for telegram.

But the issue of bot not reponding first in normal rasa run actions -p 5002 & rasa shell --debug command, is still not solved. Here is my logs :

It still works and replies, but dosn’t start the conversation. Any thing I might be missing ?

Thanks, Cheers.

I believe by default, the bot will not “start” (as in run the action_session_start) the conversation in rasa shell unless you explicitly send a message /session_start. Sessions don’t begin unless Rasa is receives an event.

In the docs you’ll see that there’s no proactive action that Rasa takes, unless triggered by an external event, so you won’t see the bot do anything in rasa shell until you send a message or send the slash command /session_start. It might be a good idea for this to be added as a behavior in a PR!

Let me know if that’s confusing!

1 Like

Thanks for the Quick reply .

I understand now. Rasa won’t start unless you sent a /session_start. So, the option is to configure the UI or channel to do that explicitly , so that the action is run.

That helps a lot. :slight_smile:

Thanks you.

Just created an issue for this here since I think others might have similar confusion!

Cool man, it’ll be cool if Rasa had that.

That can be helpful. Maybe they designed it this way might have designed it with a bigger picture in mind. Maybe for security or something…

Someone commented in the below the issue.

Hey @niveK ,

I need a bit guidance again. This is a totally different issue. So my apologies for coming out of nowhere.

But basically,

I have an image in my project directory. My bot is hosted on telegram via ngrok.

I have a custom action, to display the image as well. I tried using `

dispatcher.utter_message(image="/p1.png")

` But it dosn’t display the image.

What path do I give to display the image?

Thanks

Cheers

Images are intended to be just special hyperlinks that sometimes get rendered by the channel, spending on support. You’d want to just upload the image to a hosting site like Cloudinary and replace the path with a link.

Thanks for your help.

I used Imgur to solve the issue, it works now.