I am using Rasa 2.4 and I tried to customize the ActionSessionStart class just to send a specific user message when triggering /session_start following the below code:
class ActionSessionStart(Action):
def name(self) -> Text:
return "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", "phone_number"):
value = tracker.get_slot(key)
if value is not None:
slots.append(SlotSet(key=key, value=value))
return slots
async def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:
# the session should begin with a `session_started` event
events = [SessionStarted()]
dispatcher.utter_message(text="Bonjour Matthieu, bienvenu dans cette nouvelle session en ma compagnie !")
# an `action_listen` should be added at the end as a user message follows
events.append(ActionExecuted("action_listen"))
return events
However, when launching rasa shell and initiating with /session_start I got twice the user message: Bonjour Matthieu, bienvenu dans cette nouvelle session en ma compagnie !
Hi @mattvan83, I tried to recreate the same scenario as you have done & I too have received the same message twice, after I debugged the issue, I got to know that the action_session_start has been triggered twice for the first time, it’s because, for the initially when you start the server and type the /session_start, it tries to call the action_session_start as shown below
021-03-31 11:04:47 DEBUG rasa.core.processor - Starting a new session for conversation ID '76919d5f9f2d43c194b06f773f223563'.
2021-03-31 11:04:47 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_session_start'.
then it takes the user input and passes it to rasa nlu as show below
2021-03-31 11:04:47 DEBUG rasa.core.processor - Received user message '/session_start' with intent '{'name': 'session_start', 'confidence': 1.0}' and entities '[]'
so then it predicts action_session_start with the user intent
2021-03-31 11:04:47 DEBUG rasa.core.policies.rule_policy - Predicted default action 'action_session_start'.
2021-03-31 11:04:47 DEBUG rasa.core.policies.ensemble - Made prediction using user intent.
2021-03-31 11:04:47 DEBUG rasa.core.policies.ensemble - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-03-31 11:04:47 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_2_RulePolicy.
2021-03-31 11:04:47 DEBUG rasa.core.processor - Predicted next action 'action_session_start' with confidence 1.00.
2021-03-31 11:04:47 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_session_start'.
So what I’m trying to say is whenever you start the conversation with the bot for the first time I mean beginning of the conversation, the action_session_start is triggered by default as mentioned here
Would you see a way to deal with this problem (as not interpreting /session_start with rasa nlu or other…), since like the documentation says overriding the action_session_start could be used to start the conversation with a bot message… but not with duplicated message?
Or could I easily integrate your solution using .js script within my own chatbot to start with custom action ?
I am quite new to rasa so could you provide me a quick example on how to run this api (Rasa Open Source Documentation) that differs from the classical definition of custom action in actions.py file ?
How is recorded this custom action sent via external action server API ? Is it recorder in the tracker ?
Is it useful to use ansycnhronous protocol ? I see that you use requests which is synchronous and I recently saw in the helpdesk-assistant rasa bot (GitHub - RasaHQ/helpdesk-assistant) that many run methods within custom actions used async definition?
I didn’t get what you mean by How is recorded this custom action ?
I mean that usually custom action is triggered by the dialogue management system which has predicted it following the identification of intent from an upstream user message. Since we launch this custom action at first time connexion, there is no upstream user message from which intent then action were predicted. Since Tracker object records everything, is this custom action also recorded the same way as other actions in Tracker ?
You can check my custom action’s code in which I have used UserUtternaceReverted Event which actually revert backs everything in the trackers before the event which was triggered
So, I see where to define this custom action in the actions.py file. But where do I have to place the following code below calling the action server API in order to execute first this specific custom action?
Hi @JiteshGaikwad, I assume you get millions of people asking you about your great widget! But could you explain hoe can one trigger the custom action from your front end and also pass an entity value with that trigger? Specifically, I get an ID of users (not related to RASA user ID) from the URL and would like to pass it to the RASA bot. Is there a way how one can achieve this with your front end?