Custom action_session_start is causing errors

Hi everyone

When I try to use the dispatcher.utter_message(“hello”) to send messages to the user from the ActionSessionStart, the error: AttributeError: ‘NoneType’ object has no attribute ‘send_response’ occurs

When a try to do the same using template I get this error: ERROR rasa.core.processor - Encountered an exception while running action ‘action_session_start’. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.

this is the code

class ActionSessionStart(Action): def name(self): return “action_session_start”

async def run(self, dispatcher, tracker, domain):
    events = [SessionStarted()]
    dispatcher.utter_message(template="utter_greet")
    events.append(ActionExecuted("action_listen"))
    return events

what can I do to avoid those errors?

Hi there, i have the similar problem as well. Based from the Rasa documentation, we can override the default actions by manually adding it as a custom action in both actions.py and domain.yml. Yet, I get the same error AttributeError: ‘NoneType’ object has no attribute ‘send_response’. However, i do notice that once i start initiating a simple “Hi”, the supposedly first liner message variable will appear. But before i give any response, it will not show up as what i intended to. Can anyone share any opinion on this?

actions.py

class ActionSessionStarted(Action):
    def name(self):
        return "action_session_start"
    async def run(self, dispatcher, tracker, domain):
        events = [SessionStarted()]
        message = 'Hello, I am a ChatBot'
        dispatcher.utter_message(message)
        events.append(ActionExecuted("action_listen"))
        return events

domain.yml

actions:
- actions_session_start

Hello,

I had the same problem, in my case was an indentation on domain.yml.

I had an intent with a trigger with the wrong indentation like below:

- insult:
  triggers: utter_sorry

And the correct was:

- insult:
    triggers: utter_sorry

Even if this isn’t your case I suggest look more carefully at the error and the location inside the RASA, in my case I was able to found looking at the source. The error message told me where to look:

File “c:\venv\lib\site-packages\rasa\core\domain.py”, line 288, in _transform_intent_properties_for_internal_use properties.setdefault(USE_ENTITIES_KEY, True) AttributeError: ‘NoneType’ object has no attribute ‘setdefault’

2 Likes

@Wy0024 @Saul can you confirm if this error still occurs? Triggering a template response defined in the domain with

responses:
  utter_greet:
  - text: "Hey! How are you?"

in a custom ActionSessionStart should work with:

dispatcher.utter_message(template="utter_greet")

As you pointed out, it’s important that the custom action is listed in domain.yml:

actions:
  - action_session_start

Please let me know :slight_smile:

Hey @ricwo ,

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.( ngrok is running in port 5005, so earlier I got error as action server can’t be started.) 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:?

@Saul Any luck ??

Would you mind running both rasa run and rasa run actions -p 5002 with the --debug option again and posting logs?

Hey , @ricwo

I just found a temporary workaround for telegram. 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 realized the above issue is actually a feature of Rasa Here.

Guess it’s the default behaviour Rasa had in place taking security into consideration.:slight_smile:

Would you mind posting separate --debug logs for rasa run actions and rasa run/shell?

@ricwo @_sanjay_r @lluchini i am using the ActionSessionStart in cutom Action. I had to dispatch button in this template-

My buttons are printing in the logs but are not visible in the bot output. Why is this happening??

Hello @pranay_raj,

The session start won’t utter back because it’s an internal event from RASA.

I made this work using the initial payload from chat component, I send the initial payload as /greet like the user would, so the bot answers back.

2 Likes

How to initialize slots using action_start_session