Custom session start not working

Hi, I am trying to add some slots when the session starts. But it seems session start action that I created does run at all. Here’s the code snippet:

class ActionSessionStart(Action):
    def name(self) -> Text:
        return "action_session_start"

    def __validate_user(self, phone_no:int):
        user_profile = None
        if is_valid_user(phone_no):
            user_profile = get_user_info_from_db(phone_no)
        return user_profile

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

        slots = []
        for key in ("name", "number","is_logged_in"):
            value = tracker.get_slot(key)
            if value is not None:
                slots.append(SlotSet(key=key, value=value))
        return slots

    async def run(
      self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]
    ) -> List[Dict[Text, Any]]:
        user_events = []
        events = [SessionStarted()]
        print("hello")
        logged_in = tracker.get_slot("is_logged_in")
        if not logged_in:
            tracker_events = tracker.current_state()["events"]
            for e in tracker_events:
                if e["event"] == "user":
                    user_events.append(e)
            user_token = user_events[-1]["metadata"].get("user_token", None)
            user_profile = self.__validate_user(user_token)
            events.append(SlotSet("number", user_profile.phone))
            events.append(SlotSet("name", user_profile.first_name))
            events.append(SlotSet("is_logged_in", True))
        else:
            events.extend(self.fetch_slots(tracker))

        events.append(ActionExecuted("action_greet"))

        return events
1 Like

Hi @Horizon733 ,

Did you mention action_session_start in your domain file?

yes I did, just a quick update. Action has been recognized I don’t know how but I had to delete my old models. But now it gets [] ← events. So, can anyone help?

Eventually it started working. It was issue while fetching data from tracker.events