From e992f14522998e318fb4e5f30f280fcd2748a72a Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 25 Jul 2020 01:08:12 -0400 Subject: [PATCH] slack-bridge: Use WebClient to post message in Slack. --- .../integrations/bridge_with_slack/run-slack-bridge | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zulip/integrations/bridge_with_slack/run-slack-bridge b/zulip/integrations/bridge_with_slack/run-slack-bridge index 53d630c..40ef5fc 100755 --- a/zulip/integrations/bridge_with_slack/run-slack-bridge +++ b/zulip/integrations/bridge_with_slack/run-slack-bridge @@ -45,6 +45,9 @@ class SlackBridge: # slack-specific self.channel = self.slack_config["channel"] self.slack_client = slack.RTMClient(token=self.slack_config["token"], auto_reconnect=True) + # Spawn a non-websocket client for getting the users + # list and for posting messages in Slack. + self.slack_webclient = slack.WebClient(token=self.slack_config["token"]) def wrap_slack_mention_with_bracket(self, zulip_msg: Dict[str, Any]) -> None: words = zulip_msg["content"].split(' ') @@ -66,16 +69,14 @@ class SlackBridge: self.wrap_slack_mention_with_bracket(msg) slack_text = SLACK_MESSAGE_TEMPLATE.format(username=msg["sender_full_name"], message=msg["content"]) - self.slack_client.rtm_send_message( - self.channel, - slack_text, + self.slack_webclient.chat_postMessage( + channel=self.channel, + text=slack_text, ) return _zulip_to_slack def run_slack_listener(self) -> None: - # spawn a non-websocket client for getting the users list - _wc = slack.WebClient(token=self.slack_config["token"]) - members = _wc.users_list()['members'] + members = self.slack_webclient.users_list()['members'] # See also https://api.slack.com/changelog/2017-09-the-one-about-usernames self.slack_id_to_name = {u["id"]: u["profile"].get("display_name", u["profile"]["real_name"]) for u in members} self.slack_name_to_id = {v: k for k, v in self.slack_id_to_name.items()}