Custom action (greeting user) from POST is not showing message

Hi, I’m starting with RASA. I need my bot to proactively contact clients. I’m trying to wake up the bot with a post from a python script. I’ts working but not showing the message in the conversation…

I’m using the following code:

actions.py

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import UserUtteranceReverted

class ActionGreetUser(Action):

def name(self) → Text: return “action_greet_user”

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

dispatcher.utter_message("Hello, I am a BOT")

return [UserUtteranceReverted()]

initiate.py

import requests url = “http://localhost:5055/webhook/

payload=’{ “next_action”: “action_greet_user”, “tracker”: { “sender_id”: “random_user” } }’

headers = { ‘Content-Type’: ‘application/json’ }

response = requests.request(“POST”, url, headers=headers, data=payload) print(response.text)

Does anybody can help me to guess why shell is not showing the message: “Hello, I am a BOT”

This is easier implemented as a custom action_get_started, which is the standard way of greeting in Rasa. So you set up a get_started intent and in response you trigger this action:

image

And in your code the only change is in the name you return:

def name(self) → Text: return “action_get_started”

Now, if your only customization is a static text, and you don’t do API requests or DB queries, I recommend just setting a /get_started intent with an utter_get_started in the domain file, no custom action required!

For example:

I took these screenshots from this great forum post [Updated] Initial welcome message using rasa webchat. If this feature is enough, follow that post’s guide, it’s a great post!

if you’re using rasa 2.x, i think it changed its name to action_session_start Default Actions

Other than that, I’m not sure you’ll be able to do this in rasa shell without making a custom rasa shell channel. If you check out the CLI’s code in rasa, it does this verification:

and in this point in the conversation, previous_response IS None, so it will trigger line 105, giving you the input control and making you enter the /get_started intent or its associated NLU examples.

So you options are, make a custom Shell channel which you can set up and will need a little bit of searching on these forums. Inherit from rasa’s console channel and just overwrite the get_user_input method to check if it’s the first time the user’s connected and to output the get_started trigger. Or you could use another channel, for example socket.io and use an user-facing frontend…

Will this bot be deployed in any way? If that’s the case, it’s easier to send a /get_started as an initial payload on connection, which is a feature already included out of the box in botfront’s webchat

Hope this helps!