Skip to content

Commit ff12189

Browse files
committed
slack bridge: Add logic to prevent looping messages.
When using Slack Webhook integration to get messages from Slack to Zulip, we don't want to send back messages from the Slack integration bot. This prevents that by filtering out any messages from the Slack Webhook bots when sending messages from Zulip to Slack.. Fixes #825.
1 parent 35055f1 commit ff12189

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

zulip/integrations/bridge_with_slack/bridge_with_slack_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"email": "[email protected]",
44
"api_key": "put api key here",
55
"site": "https://chat.zulip.org",
6+
"integration_bot_email": "[email protected]",
67
},
78
"slack": {
89
"username": "slack_username",

zulip/integrations/bridge_with_slack/run-slack-bridge

+7-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ class SlackBridge:
8484
if w.startswith("@"):
8585
zulip_msg["content"] = zulip_msg["content"].replace(w, "<" + w + ">")
8686

87+
def is_message_from_slack(self, msg: Dict[str, Any]) -> bool:
88+
# Check whether or not this message is from Slack to prevent
89+
# them from being tossed back to Zulip.
90+
return msg["sender_email"] == self.zulip_config.get("integration_bot_email")
91+
8792
def zulip_to_slack(self) -> Callable[[Dict[str, Any]], None]:
8893
def _zulip_to_slack(msg: Dict[str, Any]) -> None:
8994
slack_channel = get_slack_channel_for_zulip_message(
9095
msg, self.zulip_to_slack_map, self.zulip_config["email"]
9196
)
92-
if slack_channel is not None:
97+
98+
if slack_channel is not None and not self.is_message_from_slack(msg):
9399
self.wrap_slack_mention_with_bracket(msg)
94100
slack_text = SLACK_MESSAGE_TEMPLATE.format(
95101
username=msg["sender_full_name"], message=msg["content"]

0 commit comments

Comments
 (0)