Integrate Rasa Open Source with Slack using Socket Mode and custom connector

Hello Rasa community! Our purpose is to built a Rasa chatbot and integrate it with a Slack channel using Socket Mode. For this we followed Rasa documentation and this very useful article.

We successfully managed to integrate the Rasa bot with our Slack channel but now we are working on making the bot only reply when the intent is identified in a channel message and not in a thread reply message. To be able to achieve this we are trying to verify if the latest message has a “thread_ts” as per the following documentation and if an intent is identified in it. If these conditions are met the bot will not reply. Unfortunately, when trying to use the “DialogueStateTracker” or “Tracker” class we receive the following error:

2023-05-19 13:22:14 ERROR    slack_sdk.socket_mode.builtin.client  - Failed to run a request listener: SlackWithSocketInput._handle_message() missing 1 required positional argument: 'tracker'
Traceback (most recent call last):
  File "C:\chatbot\venv\lib\site-packages\slack_sdk\socket_mode\client.py", line 144, in run_message_listeners
    listener(self, request)  # type: ignore
TypeError: SlackWithSocketInput._handle_message() missing 1 required positional argument: 'tracker'

Our story is simple, the intent is identified and the bot is asking for the username of the user in a slot and unblock their account using a Rasa custom action:

 - story: unblock path
  steps:
  - intent: unblock_user
  - action: utter_unblock
  - action: username_form
  - active_loop: username_form
  - action: action_restart

The custom action is executed successfully when we are not using the “tracker: DialogueStateTracker” in our custom connector script. We encounter the error only when we configure the “_handle_message” function like this:

def _handle_message(self, client: SocketModeClient, req: SocketModeRequest, tracker: DialogueStateTracker) -> None:  
        
        
        if req.type == "events_api":
            response = SocketModeResponse(envelope_id=req.envelope_id)
            self.socket_client.send_socket_mode_response(response)
            #the bellow lines check if the message is a thread reply and if it matches any intent
            if req.payload["event"].get("thread_ts") and tracker.latest_message.intent.get(INTENT)=="unblock_user":
                return
            else:

                if req.payload["event"]["type"] == "message" \
                        and req.payload["event"].get("subtype") is None:
                    
                    if req.payload["event"]["user"] != self.slack_bot_user_id:
                        print(req.payload)
                        thread_id = req.payload["event"].get("ts")
                        parent_user_id = req.payload["event"].get("parent_user_id")
                        if thread_id and parent_user_id == self.slack_bot_user_id:
                            return
                        user_message = UserMessage(req.payload["event"]["text"],
                                                    self.get_output_channel(req.payload["event"]["channel"], thread_id),
                                                    req.payload["event"]["user"])
                        asyncio.run(self.on_new_message(user_message))

If I check the line code from the file mentioned in the error I can’t identify any issues with it:

for listener in self.socket_mode_request_listeners:
                        try: #line 143
                            listener(self, request)  # 

If we remove the “tracker: DialogueStateTracker” from the “_handle_message” function and we remove the logic that checks if the latest message intent matches our intents, the bot runs successfully, but it also replies if the thread is identified in a thread reply message, which is not the behavior we want.

We are new to Rasa so we apologize in advance for any mistake we made in our code. Could someone please advice on how we can solve this issue or how we can achieve our desired behavior?

Thank you in advance!