Skip to content

Commit 4e8c1d1

Browse files
Niloth-ptimabbott
authored andcommitted
google-calendar: Use a bot to send direct messages to the bot owner.
The reminders were previously being sent to the DMs of the current user, requiring the zuliprc of the user. But, we can create a generic bot for the Google Calendar integration, and use its zuliprc to send direct messages to its owner. This tightens security. The support for sending DMs to the same user is retained, for cases where a bot is not used.
1 parent eff3809 commit 4e8c1d1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

zulip/integrations/google/google-calendar

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ sent: Set[Tuple[int, datetime.datetime]] = set()
2929

3030
sys.path.append(os.path.dirname(__file__))
3131

32-
usage = r"""google-calendar [--interval MINUTES] [--calendar CALENDAR_ID]
32+
usage = r"""google-calendar [--config-file PATH_TO_ZULIPRC_OF_BOT]
33+
[--interval MINUTES] [--calendar CALENDAR_ID]
3334
3435
This integration can be used to send Zulip messages as reminders for upcoming events from your Google Calendar.
3536
36-
Specify your Zulip API credentials and server in a ~/.zuliprc file, or using the options.
37-
38-
This integration should be run on your local machine, as your API key is accessible to local users through the command line.
37+
Create a generic bot on Zulip, download its zuliprc file, and use the --config-file option to specify the path to your bot's zuliprc.
3938
4039
For more information, see https://zulip.com/integrations/doc/google-calendar.
4140
"""
@@ -162,8 +161,13 @@ def send_reminders() -> Optional[None]:
162161
else:
163162
message = "Reminder:\n\n" + "\n".join("* " + m for m in messages)
164163

164+
user_profile = zulip_client.get_profile()
165165
result = zulip_client.send_message(
166-
{"type": "direct", "to": [zulip_client.get_profile()["email"]], "content": message}
166+
{
167+
"type": "direct",
168+
"to": [user_profile.get("bot_owner_id") or user_profile["email"]],
169+
"content": message,
170+
}
167171
)
168172
if result["result"] != "success":
169173
logging.error("Error sending zulip message: %s: %s", result.get("code"), result.get("msg"))

0 commit comments

Comments
 (0)