Skip to content

Commit e7fa631

Browse files
Niloth-ptimabbott
authored andcommitted
google-calendar: Support sending reminders to channels.
Previously, until last commit, the zuliprc of the user was being used directly. Now that we're using the zuliprc of a bot, it is safe for multiple users with a shared calendar to have a bot send the reminders to a channel. Added channel and topic arguments, with the default behavior set to sending a direct message.
1 parent 4e8c1d1 commit e7fa631

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

zulip/integrations/google/google-calendar

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sys.path.append(os.path.dirname(__file__))
3131

3232
usage = r"""google-calendar [--config-file PATH_TO_ZULIPRC_OF_BOT]
3333
[--interval MINUTES] [--calendar CALENDAR_ID]
34+
[--channel CHANNEL_NAME] [--topic TOPIC_NAME]
3435
3536
This integration can be used to send Zulip messages as reminders for upcoming events from your Google Calendar.
3637
@@ -52,6 +53,15 @@ parser.add_argument(
5253
default="primary",
5354
help="The ID of the calendar you want to receive reminders from. By default, the primary calendar is used.",
5455
)
56+
parser.add_argument(
57+
"--channel",
58+
help="The channel to which to send the reminders to. By default, messages are sent to the DMs of the bot owner.",
59+
)
60+
parser.add_argument(
61+
"--topic",
62+
help="The topic to which to send the reminders to. Ignored if --channel is unspecified. 'calendar-reminders' is used as the default topic name.",
63+
default="calendar-reminders",
64+
)
5565
options = parser.parse_args()
5666

5767
zulip_client = zulip.init_from_options(options)
@@ -162,13 +172,18 @@ def send_reminders() -> Optional[None]:
162172
message = "Reminder:\n\n" + "\n".join("* " + m for m in messages)
163173

164174
user_profile = zulip_client.get_profile()
165-
result = zulip_client.send_message(
166-
{
167-
"type": "direct",
168-
"to": [user_profile.get("bot_owner_id") or user_profile["email"]],
169-
"content": message,
170-
}
171-
)
175+
if options.channel is not None:
176+
result = zulip_client.send_message(
177+
{"type": "stream", "to": options.channel, "topic": options.topic, "content": message}
178+
)
179+
else:
180+
result = zulip_client.send_message(
181+
{
182+
"type": "direct",
183+
"to": [user_profile.get("bot_owner_id") or user_profile["email"]],
184+
"content": message,
185+
}
186+
)
172187
if result["result"] != "success":
173188
logging.error("Error sending zulip message: %s: %s", result.get("code"), result.get("msg"))
174189
sent.update(keys)

0 commit comments

Comments
 (0)