diff --git a/slack_server_mock/servers/http/handler.py b/slack_server_mock/servers/http/handler.py index 6ffc146..c375a9e 100644 --- a/slack_server_mock/servers/http/handler.py +++ b/slack_server_mock/servers/http/handler.py @@ -143,3 +143,25 @@ def post(self): While the documentation states that this is a GET command, the SDK calls PUT """ self._handle() + + +class ConversationsJoinHandler(BaseSlackHandler): # pylint: disable=W0223 + """ Handler for conversations.join endpoint """ + def post(self): + """ Handle POST request """ + if not self._is_request_valid(): + return + + arg = self.request.body.decode("utf-8").split('=') + if not (len(arg) == 2 and arg[0] == "channel"): + self.set_status(400) + self.write({"error": "Invalid argument"}) + return + + channels = [ + channel for channel in global_injector.get(SlackServer).channels if channel['id'] == arg[1] + ] + if len(channels) == 0: + self.write({"ok": False, "error": "channel_not_found"}) + else: + self.write({"ok": True, "channel": channels[0]}) diff --git a/slack_server_mock/servers/http/server.py b/slack_server_mock/servers/http/server.py index 2f27bdb..2457b65 100644 --- a/slack_server_mock/servers/http/server.py +++ b/slack_server_mock/servers/http/server.py @@ -20,6 +20,7 @@ def __init__(self, settings: Settings) -> None: (r"/apps.connections.open", handler.AppsConnectionsOpenHandler), (r"/api.test", handler.ApiTestHandler), (r"/chat.postMessage", handler.ChatPostMessageHandler), + (r"/conversations.join", handler.ConversationsJoinHandler), (r"/conversations.list", handler.ConversationsListHandler), ] )