Skip to content

Commit 6e97d4e

Browse files
committed
bridge_between_zulip: Check if the bots are subscribed to relevant streams.
Check whether both the bots are subscribed to their respective streams designated for sending messages before starting the bridge. Fixes #568.
1 parent 4b7119b commit 6e97d4e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

zulip/integrations/bridge_between_zulips/run-interrealm-bridge

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import interrealm_bridge_config
99

1010
from typing import Any, Callable, Dict
1111

12+
def check_subscription_or_die(zulip_client, stream):
13+
# type: (zulip.Client, str) -> None
14+
resp = zulip_client.list_subscriptions()
15+
if resp["result"] != "success":
16+
print("ERROR: %s" % (resp["msg"],))
17+
sys.exit(1)
18+
subs = [s["name"] for s in resp["subscriptions"]]
19+
if stream not in subs:
20+
print("The bot is not yet subscribed to stream '%s'. Please subscribe the bot to the stream first." % (stream,))
21+
sys.exit(1)
1222

1323
def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
1424
to_bot: Dict[str, Any], stream_wide: bool
@@ -84,6 +94,9 @@ if __name__ == "__main__":
8494
site=bot1["site"])
8595
client2 = zulip.Client(email=bot2["email"], api_key=bot2["api_key"],
8696
site=bot2["site"])
97+
# Check whether zulip bots are subscribed to their respective streams or not
98+
check_subscription_or_die(client1, bot1["stream"])
99+
check_subscription_or_die(client2, bot2["stream"])
87100
# A bidirectional tunnel
88101
pipe_event1 = create_pipe_event(client2, bot1, bot2, args.stream)
89102
p1 = mp.Process(target=client1.call_on_each_event, args=(pipe_event1, ["message"]))

0 commit comments

Comments
 (0)