|
1 |
| -Get Google Calendar reminders in Zulip! This is a great way to see |
2 |
| -your reminders directly in your Zulip feed. |
| 1 | +# Zulip Google Calendar integration |
3 | 2 |
|
4 |
| -1. {!download-python-bindings.md!} |
| 3 | +Get Zulip notifications for your Google Calendar events! |
5 | 4 |
|
6 |
| - This bot should be set up on a trusted machine, because your API |
7 |
| - key is visible to local users through the command line or config |
8 |
| - file. |
| 5 | +### Create Zulip bot for Google Calendar notifications |
9 | 6 |
|
10 |
| -1. Next, follow the instructions for **Step 1** at |
11 |
| - [this link](https://developers.google.com/google-apps/calendar/quickstart/python) |
12 |
| - to get a `client_secret` file. Save this file as `client_secret.json` |
13 |
| - to your `~/` directory. |
| 7 | +{start_tabs} |
14 | 8 |
|
15 |
| -1. Next, install the latest Google API Client for Python by following the |
16 |
| - instructions on the |
17 |
| - [Google website](https://developers.google.com/api-client-library/python/start/installation). |
| 9 | +1. {!create-a-generic-bot.md!} |
18 | 10 |
|
19 |
| -1. In Zulip, go to your click on the cog in the top right corner, and |
20 |
| - then clicking on **Personal settings**. |
| 11 | +1. [Download your bot's `zuliprc` file][download-zuliprc], and save it as |
| 12 | + `.zuliprc` in your `~/` directory. |
21 | 13 |
|
22 |
| -1. Click on the tab that’s labeled **Account & privacy** and click on |
23 |
| - **Manage your API key**. Enter your password if prompted, and |
24 |
| - download the `zuliprc` file. Save this file as `.zuliprc` to your `~/` |
25 |
| - directory. |
| 14 | +[download-zuliprc]: /api/configuring-python-bindings#download-a-zuliprc-file |
26 | 15 |
|
27 |
| -  |
| 16 | +1. Optionally, to configure the bot, add a **`google-calendar`** section to |
| 17 | + the `.zuliprc` file, like below: |
28 | 18 |
|
29 |
| -1. Run the `get-google-credentials` with this command: |
| 19 | + ``` |
| 20 | + [google-calendar] |
| 21 | + interval=30 |
| 22 | + channel=core-team |
| 23 | + topic=scheduled events |
| 24 | + ``` |
30 | 25 |
|
31 |
| - python /usr/local/share/zulip/integrations/google/get-google-credentials |
| 26 | + See [configuration options](#configuration-options) for the list of |
| 27 | + available options. |
32 | 28 |
|
33 |
| -1. It should open up a browser and ask you for certain permissions. Give |
34 |
| - Zulip access, and move on to the next step. If it doesn’t open a |
35 |
| - browser, follow the instructions in the terminal window. |
| 29 | +{end_tabs} |
36 | 30 |
|
37 |
| -1. Now, all that’s left to do is to run the `gcal-bot` script, in the |
38 |
| - same directory as the `get-google-credentials` script, with the |
39 |
| - necessary parameters: |
| 31 | +### Setup Google OAuth Client ID |
40 | 32 |
|
41 |
| - python /usr/local/share/zulip/integrations/google/gcal-bot --user [email protected] |
| 33 | +{start_tabs} |
42 | 34 |
|
43 |
| - The `--user` flag specifies the user to send the reminder to. |
| 35 | +!!! tip "" |
44 | 36 |
|
45 |
| -1. Don’t close the terminal window with the bot running (you can use |
46 |
| - `screen` if needed). You will only get reminders if the bot is still |
47 |
| - running. |
| 37 | + A free Google account is sufficient for this integration; a Google |
| 38 | + service account is not required. |
48 | 39 |
|
49 |
| -{!congrats.md!} |
| 40 | +1. In the Google Cloud console, go to |
| 41 | + **Menu > Google Auth platform > [Branding][branding-menu]**. If you see |
| 42 | + a message that says **Google Auth platform not configured yet**, click |
| 43 | + **Get Started**, and fill the form with the following details. |
50 | 44 |
|
51 |
| - |
| 45 | + - Under **App Information**, set **App name** to a name of your choice. |
| 46 | + Set **User support email** to your email address from the dropdown. |
| 47 | + Click **Next**. |
| 48 | + - Under **Audience**, select **External**, and click **Next**. |
| 49 | + - Under **Contact Information**, enter your email address, and click |
| 50 | + **Next**. |
| 51 | + - Under **Finish**, review the |
| 52 | + **Google API Services User Data Policy** and if you agree, select |
| 53 | + **I agree**. Click **Continue**, and click **Create**. |
52 | 54 |
|
53 |
| -## Supported parameters |
| 55 | +1. Go to the **[Clients][clients-menu]** tab. Click **Create Client**. |
| 56 | + Select **Application type > Desktop app**. Set **Name** to a name of |
| 57 | + your choice, such as `Zulip`, and click **Create**. Save the downloaded |
| 58 | + JSON file as `client_secret.json` in your `~/` directory. |
54 | 59 |
|
55 |
| -There are two optional flags that you can specify when running this |
56 |
| -script: |
| 60 | +1. Go to the **[Audience][audience-menu]** tab. Under **Test users**, click **+ Add Users**. |
| 61 | + Enter the email address corresponding to your Google Calendar, and click |
| 62 | + **Save**. |
57 | 63 |
|
58 |
| -* `--calendar`: This flag specifies the calendar to watch from the |
59 |
| - user’s Google account. By default, this flag is set to a user’s |
60 |
| - primary or default calendar. To specify a calendar, you need the |
61 |
| - calendar ID which can be obtained by going to Google Calendar and |
62 |
| - clicking on the wedge next to the calendar’s name. Click on settings |
63 |
| - in **Calendar settings** in the drop down, and look for the **Calendar |
64 |
| - Address** section. Copy the **Calendar ID** from the right side of the |
65 |
| - page and use that as the value for this flag. |
| 64 | +[branding-menu]: https://console.cloud.google.com/auth/branding |
| 65 | +[clients-menu]: https://console.cloud.google.com/auth/clients |
| 66 | +[audience-menu]: https://console.cloud.google.com/auth/audience |
66 | 67 |
|
67 |
| - |
| 68 | +{end_tabs} |
68 | 69 |
|
69 |
| -* `--interval`: This flag specifies the interval of time - in |
70 |
| - minutes - between receiving the reminder, and the actual event. For |
71 |
| - example, an interval of 30 minutes would mean that you would receive a |
72 |
| - reminder for an event 30 minutes before it is scheduled to occur. |
| 70 | +### Run the integration script |
| 71 | +
|
| 72 | +{start_tabs} |
| 73 | +
|
| 74 | +1. Download and |
| 75 | + [install the Zulip Python API](/api/installation-instructions) with: |
| 76 | +
|
| 77 | + `pip install zulip` |
| 78 | +
|
| 79 | +1. Install the requirements for the integration script with: |
| 80 | +
|
| 81 | + `python {{ integration_path }} --provision` |
| 82 | +
|
| 83 | +1. Run the integration script with: |
| 84 | +
|
| 85 | + `python {{ integration_path }}` |
| 86 | +
|
| 87 | + Authorize access in the browser window that opens, to allow the Zulip |
| 88 | + bot to view your Calendar. If you've set `noauth_local_webserver` to |
| 89 | + true, follow the terminal prompts instead, and paste the resulting |
| 90 | + authorization code. |
| 91 | +
|
| 92 | +1. Optionally, pass commandline arguments to configure the integration. The |
| 93 | + commandline arguments override the corresponding settings in the |
| 94 | + `.zuliprc` file. |
| 95 | +
|
| 96 | + `python {{ integration_path }} --interval 30 --channel core-team --topic "scheduled events"` |
| 97 | +
|
| 98 | + See [configuration options](#configuration-options) for the list of |
| 99 | + available options. |
| 100 | +
|
| 101 | +1. You will get notifications as long as the terminal session with the bot |
| 102 | + remains open. Consider using `screen` to run the bot in the background. |
| 103 | +
|
| 104 | +!!! tip "" |
| 105 | +
|
| 106 | + Newly added calendar events may take up to 10 minutes to generate |
| 107 | + notifications. |
| 108 | +
|
| 109 | +{end_tabs} |
| 110 | +
|
| 111 | +### Configure the integration |
| 112 | +
|
| 113 | +The integration can be configured by: |
| 114 | +
|
| 115 | +- Passing command line arguments to the integration script. |
| 116 | +- Editing the `google-calendar` section of the `zuliprc` file. |
| 117 | +
|
| 118 | +The configuration settings in `zuliprc` will be overridden by the |
| 119 | +corresponding command line options, if both are used. |
| 120 | +
|
| 121 | +### Configuration options |
| 122 | +
|
| 123 | +The integration script accepts the following configuration options: |
| 124 | +
|
| 125 | +- `interval`: How many minutes in advance you want reminders delivered. |
| 126 | + The default value is 30 minutes. |
| 127 | +
|
| 128 | +- `channel`: The name of the Zulip channel you want to receive |
| 129 | + notifications in. By default, messages are sent as direct messages to the |
| 130 | + bot's owner. |
| 131 | +
|
| 132 | +- `topic`: The name of the Zulip topic you want to receive notifications |
| 133 | + in. This option is ignored if the `channel` option is unspecified. If the |
| 134 | + `channel` option is specified, the default topic is "calendar-reminders". |
| 135 | +
|
| 136 | +- `client-secret-file`: The path to the file containing the client secret. |
| 137 | + By default, the client secret file is assumed to be at |
| 138 | + `~/client_secret.json`. |
| 139 | +
|
| 140 | +- `tokens-file`: The path to the file where the OAuth tokens are stored. By |
| 141 | + default, the tokens file is generated at `~/google-tokens.json` when the |
| 142 | + integration is first run, and is rewritten every hour. |
| 143 | +
|
| 144 | +- `noauth-local-webserver`: This option stops the integration script from |
| 145 | + starting a local webserver for receiving OAuth tokens. The default |
| 146 | + authorization process runs a local web server, which requires a browser on |
| 147 | + the same machine. For non-interactive environments and machines without |
| 148 | + browser access, e.g., remote servers, this option allows manual |
| 149 | + authorization. The authorization URL is printed, which the user can copy |
| 150 | + into a browser, copy the resulting authorization code, and paste back into |
| 151 | + the command line. |
| 152 | +
|
| 153 | +- `calendar`: The `calendar ID` of the Google calendar to get events from. |
| 154 | + By default, the `primary` calendar is used. |
| 155 | +
|
| 156 | +- `format-message`: The template for the message that is sent to Zulip. This |
| 157 | + Python f-string supports Markdown, and can use the following variables: |
| 158 | + `start`, `end`, `title`, `description`, `calendar_link`, `location`, |
| 159 | + `google_meet_link`. |
| 160 | +
|
| 161 | + !!! warn "" |
| 162 | +
|
| 163 | + **Note:** The `title`, `description`, `location`, and |
| 164 | + `google_meet_link` variables are optional for Google Calendar |
| 165 | + events, and hence may be empty. Empty fields are displayed as |
| 166 | + "{No title}", "{No description}", "{No location}", and "{No link}" |
| 167 | + in the message template. |
| 168 | +
|
| 169 | + The default message template takes the following form when all the event |
| 170 | + field variables are non-empty. |
| 171 | +
|
| 172 | + `The event [{title}]({calendar_link}), at {location}, is from {start} to {end}.\n> {description}\n\n[Join call]({google_meet_link}).` |
| 173 | +
|
| 174 | +### Related documentation |
| 175 | +
|
| 176 | +- [Google's documentation on configuring the OAuth consent screen][consent-screen] |
| 177 | +- [Google's documentation on setting up OAuth Client IDs][client-secret] |
| 178 | +
|
| 179 | +[consent-screen]: https://developers.google.com/workspace/calendar/api/quickstart/python#configure_the_oauth_consent_screen |
| 180 | +[client-secret]: https://developers.google.com/workspace/calendar/api/quickstart/python#authorize_credentials_for_a_desktop_application |
0 commit comments