Skip to content

Commit 65e0ca3

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 c069ade commit 65e0ca3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

zulip/integrations/bridge_with_slack/run-slack-bridge

Lines changed: 7 additions & 1 deletion
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("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)