Skip to content

Update Google Calendar integration #856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
352a475
google-calendar: Update requirements.txt dependencies.
Niloth-p Feb 18, 2025
81387d1
google-calendar: Replace deprecated oauth2client library.
Niloth-p Feb 18, 2025
e722e90
google-calendar: Update outdated send_message parameters.
Niloth-p Feb 18, 2025
dfe38f1
google-calendar: Narrow the permission scope to calendar events.
Niloth-p Feb 18, 2025
4b9dbb3
google-calendar: Use a constant for the tokens filename.
Niloth-p Feb 18, 2025
5b8b440
google-calendar: Fix usage of term "credentials", replace with "tokens".
Niloth-p Feb 18, 2025
2bb1b8a
google-calendar: Update command usage help.
Niloth-p Feb 18, 2025
f30a571
google-calendar: Clean up `add_argument` parameters.
Niloth-p Feb 18, 2025
f18399c
google-calendar: Add --provision argument to install dependencies.
Niloth-p Feb 18, 2025
07810c5
google-calendar: Add error handling for missing client secret file.
Niloth-p Feb 18, 2025
abf6415
google-calendar: Stop printing events unless the verbose option is set.
Niloth-p Feb 18, 2025
8b2b9dd
google-calendar: Add error handling for send_message.
Niloth-p Feb 18, 2025
06db61b
google-calendar: Improve CLIENT_SECRET_FILE occurrences.
Niloth-p Feb 18, 2025
445ee9b
google-calendar: Call get-google-credentials script internally.
Niloth-p Feb 18, 2025
8b7c536
google-calendar: Use current user's email id for send_message.
Niloth-p Feb 18, 2025
6436918
google-calendar: Use a bot to send direct messages to the bot owner.
Niloth-p Feb 18, 2025
5d3ff39
google-calendar: Support sending reminders to channels.
Niloth-p Feb 18, 2025
4c56d9b
google-calendar: Support manual authorization using auth code.
Niloth-p Feb 18, 2025
441dce9
google-calendar: Log writing to the tokens file.
Niloth-p Feb 18, 2025
c004199
google-calendar: Add options --client-secret-file and --tokens-file.
Niloth-p Feb 18, 2025
9ced7b8
google-calendar: Support loading options from the zuliprc.
Niloth-p Feb 19, 2025
e38a8e6
google-calendar: Fix type of event id, switch from int to str.
Niloth-p Feb 19, 2025
da6d896
google-calendar: Send each reminder as its own message.
Niloth-p Feb 19, 2025
8794800
google-calendar: Add TypedDict and string conversion function for event.
Niloth-p Feb 19, 2025
b468931
google-calendar: Generalize the datetime parsing for event fields.
Niloth-p Feb 19, 2025
078d307
google-calendar: Display more Event info in reminder messages.
Niloth-p Feb 19, 2025
974863e
google-calendar: Support user customization of the message template.
Niloth-p Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions zulip/integrations/google/google-calendar
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class GoogleCalendarOptions:
noauth_local_webserver: bool = False
tokens_path: str = TOKENS_PATH
client_secret_path: str = CLIENT_SECRET_PATH
format_message: Optional[str] = None


class Event(TypedDict):
Expand Down Expand Up @@ -69,6 +70,7 @@ usage = r"""google-calendar [--config-file PATH_TO_ZULIPRC_OF_BOT]
[--client-secret-file PATH_TO_CLIENT_SECRET_FILE]
[--tokens-file PATH_TO_GOOGLE_TOKENS_FILE]
[-n] [--noauth_local_webserver]
[-f MESSAGE_TEMPLATE] [--format-message MESSAGE_TEMPLATE]

This integration can be used to send Zulip messages as reminders for upcoming events from your Google Calendar.

Expand Down Expand Up @@ -112,6 +114,11 @@ parser.add_argument(
action="store_true",
help="The default authorization process runs a local web server, which requires a browser on the same machine. For non-interactive environments and machines without browser access, e.g., remote servers, this option allows manual authorization. The authorization URL is printed, which the user can copy into a browser, copy the resulting authorization code, and paste back into the command line.",
)
parser.add_argument(
"-f",
"--format-message",
help="A Python f-string to use to format the markdown message template. This option overrides the default message template. The f-string can use the following variables: start, end, title, description, calendar_link, location, google_meet_link.\nNote that the title, description, location, and google_meet_link variables are optional for Google Calendar events, and hence may be empty. Empty fields are displayed as {No title}, {No description}, {No location}, and {No link} in the message template.",
)
commandline_options = parser.parse_args()
if commandline_options.verbose:
logging.getLogger().setLevel(logging.INFO)
Expand Down Expand Up @@ -251,6 +258,19 @@ def populate_events() -> Optional[None]:


def construct_message_from_event(event: Event) -> str:
if calendar_options.format_message:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature might be overkill. I guess I'll merge it.

message = calendar_options.format_message.format(
start=event["start"].strftime("%Y-%m-%d %H:%M"),
end=event["end"].strftime("%Y-%m-%d %H:%M"),
title=event["summary"],
description=event["description"] or "{No description}",
calendar_link=event["html_link"],
location=event["location"] or "{No location}",
google_meet_link=event["hangout_link"] or "{No link}",
)
decoded_message = bytes(message, "utf-8").decode("unicode_escape")
return decoded_message

time_period = (
"today"
if event["start"].hour == 0 and event["start"].minute == 0
Expand Down
Loading