# Custom action\_session\_start is causing errors

**URL:** <https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797>\
**Category:** Rasa Open Source\
**Created:** [January 22, 2020, 12:05am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797 "2020-01-22T00:05:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saul](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@Saul](https://forum.rasa.com/u/Saul)\
**Post date:** [January 22, 2020, 12:05am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/1 "2020-01-22T00:05:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wy0024](https://avatars.discourse-cdn.com/v4/letter/w/57b2e6/32.png) [@Wy0024](https://forum.rasa.com/u/Wy0024)\
**Post date:** [February 4, 2020, 2:26am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/2 "2020-02-04T02:26:47Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![lluchini](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lluchini/32/7609_2.png) [@lluchini](https://forum.rasa.com/u/lluchini)\
**Post date:** [March 23, 2020, 12:57pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/3 "2020-03-23T12:57:26Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![ricwo](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@ricwo](https://forum.rasa.com/u/ricwo)\
**Post date:** [March 23, 2020, 7:29pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/4 "2020-03-23T19:29:47Z")

</div>

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

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

```

in a custom `ActionSessionStart` should work with:

```python
dispatcher.utter_message(template="utter_greet")

```

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

```auto
actions:
  - action_session_start

```

Please let me know 🙂

---

<div class="post-metadata">

**Author:** ![\_sanjay\_r](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/_sanjay_r/32/4451_2.png) [@\_sanjay\_r](https://forum.rasa.com/u/_sanjay_r)\
**Post date:** [April 14, 2020, 8:21pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/5 "2020-04-14T20:21:36Z")

</div>

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…

1. 

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/6/697b5d07e425e19db5b024d98aefd62b8596a543.png)

1. 

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/6/65ba334b0feb2013f81e84b5261e8016c13000ca.png)

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

@Saul Any luck ??

---

<div class="post-metadata">

**Author:** ![ricwo](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@ricwo](https://forum.rasa.com/u/ricwo)\
**Post date:** [April 15, 2020, 8:00am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/6 "2020-04-15T08:00:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![\_sanjay\_r](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/_sanjay_r/32/4451_2.png) [@\_sanjay\_r](https://forum.rasa.com/u/_sanjay_r)\
**Post date:** [April 15, 2020, 9:56am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/7 "2020-04-15T09:56:50Z")

</div>

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.

```auto
- 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 :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/a/af7f0a1924b0407dc75b1093c0ffd13b0fd1f0a5.png)

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

Thanks,

Cheers.

---

<div class="post-metadata">

**Author:** ![\_sanjay\_r](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/_sanjay_r/32/4451_2.png) [@\_sanjay\_r](https://forum.rasa.com/u/_sanjay_r)\
**Post date:** [April 15, 2020, 7:05pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/8 "2020-04-15T19:05:10Z")

</div>

I realized the above issue is actually a feature of Rasa [Here](http://forum.rasa.com/t/chatroom-let-the-bot-start-the-conversation/2738/14).

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

---

<div class="post-metadata">

**Author:** ![ricwo](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@ricwo](https://forum.rasa.com/u/ricwo)\
**Post date:** [April 16, 2020, 6:24am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/9 "2020-04-16T06:24:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pranay\_raj](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@pranay\_raj](https://forum.rasa.com/u/pranay_raj)\
**Post date:** [April 21, 2020, 10:07pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/10 "2020-04-21T22:07:27Z")

</div>

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

> [@ricwo](#):
>
> dispatcher.utter\_message(template=“utter\_greet”)

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

---

<div class="post-metadata">

**Author:** ![lluchini](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lluchini/32/7609_2.png) [@lluchini](https://forum.rasa.com/u/lluchini)\
**Post date:** [April 22, 2020, 12:06am UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/11 "2020-04-22T00:06:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KheireddineAzzez](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kheireddineazzez/32/17869_2.png) [@KheireddineAzzez](https://forum.rasa.com/u/KheireddineAzzez)\
**Post date:** [April 6, 2021, 10:52pm UTC](https://forum.rasa.com/t/custom-action-session-start-is-causing-errors/23797/12 "2021-04-06T22:52:27Z")

</div>

How to initialize slots using action\_start\_session
