slack-bridge: Use WebClient to post message in Slack.
MODIFY
zulip/integrations/bridge_with_slack/run-slack-bridge
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()}

slack-bridge: Use WebClient to post message in Slack.