├── .github ├── CODEOWNERS ├── linters │ ├── .htmlhintrc │ ├── .yaml-lint.yml │ └── sun_checks.xml ├── sync-repo-settings.yaml └── workflows │ ├── automation.yml │ ├── lint.yml │ └── test.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── final ├── Code.gs └── appsscript.json ├── step-3 ├── Code.gs └── appsscript.json ├── step-4 ├── Code.gs └── appsscript.json ├── step-5 ├── Code.gs └── appsscript.json └── step-6 ├── Code.gs └── appsscript.json /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 16 | 17 | .github/ @googleworkspace/workspace-devrel-dpe 18 | -------------------------------------------------------------------------------- /.github/linters/.htmlhintrc: -------------------------------------------------------------------------------- 1 | { 2 | "tagname-lowercase": true, 3 | "attr-lowercase": true, 4 | "attr-value-double-quotes": true, 5 | "attr-value-not-empty": false, 6 | "attr-no-duplication": true, 7 | "doctype-first": false, 8 | "tag-pair": true, 9 | "tag-self-close": false, 10 | "spec-char-escape": false, 11 | "id-unique": true, 12 | "src-not-empty": true, 13 | "title-require": false, 14 | "alt-require": true, 15 | "doctype-html5": true, 16 | "id-class-value": false, 17 | "style-disabled": false, 18 | "inline-style-disabled": false, 19 | "inline-script-disabled": false, 20 | "space-tab-mixed-disabled": "space", 21 | "id-class-ad-disabled": false, 22 | "href-abs-or-rel": false, 23 | "attr-unsafe-chars": true, 24 | "head-script-disabled": false 25 | } 26 | -------------------------------------------------------------------------------- /.github/linters/.yaml-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ########################################### 3 | # These are the rules used for # 4 | # linting all the yaml files in the stack # 5 | # NOTE: # 6 | # You can disable line with: # 7 | # # yamllint disable-line # 8 | ########################################### 9 | rules: 10 | braces: 11 | level: warning 12 | min-spaces-inside: 0 13 | max-spaces-inside: 0 14 | min-spaces-inside-empty: 1 15 | max-spaces-inside-empty: 5 16 | brackets: 17 | level: warning 18 | min-spaces-inside: 0 19 | max-spaces-inside: 0 20 | min-spaces-inside-empty: 1 21 | max-spaces-inside-empty: 5 22 | colons: 23 | level: warning 24 | max-spaces-before: 0 25 | max-spaces-after: 1 26 | commas: 27 | level: warning 28 | max-spaces-before: 0 29 | min-spaces-after: 1 30 | max-spaces-after: 1 31 | comments: disable 32 | comments-indentation: disable 33 | document-end: disable 34 | document-start: 35 | level: warning 36 | present: true 37 | empty-lines: 38 | level: warning 39 | max: 2 40 | max-start: 0 41 | max-end: 0 42 | hyphens: 43 | level: warning 44 | max-spaces-after: 1 45 | indentation: 46 | level: warning 47 | spaces: consistent 48 | indent-sequences: true 49 | check-multi-line-strings: false 50 | key-duplicates: enable 51 | line-length: 52 | level: warning 53 | max: 120 54 | allow-non-breakable-words: true 55 | allow-non-breakable-inline-mappings: true 56 | new-line-at-end-of-file: disable 57 | new-lines: 58 | type: unix 59 | trailing-spaces: disable -------------------------------------------------------------------------------- /.github/linters/sun_checks.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 18 | 19 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 82 | 83 | 84 | 86 | 87 | 88 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 108 | 109 | 110 | 111 | 112 | 114 | 115 | 116 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 135 | 137 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 185 | 186 | 187 | 189 | 191 | 192 | 193 | 194 | 196 | 197 | 198 | 199 | 201 | 202 | 203 | 204 | 206 | 207 | 208 | 209 | 211 | 212 | 213 | 214 | 216 | 217 | 218 | 219 | 221 | 222 | 223 | 224 | 226 | 227 | 228 | 229 | 231 | 232 | 233 | 234 | 236 | 237 | 238 | 239 | 241 | 242 | 243 | 244 | 246 | 247 | 248 | 249 | 251 | 253 | 255 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 287 | 288 | 289 | 292 | 293 | 294 | 295 | 301 | 302 | 303 | 304 | 308 | 309 | 310 | 311 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 326 | 327 | 328 | 329 | 330 | 331 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 347 | 348 | 349 | 350 | 353 | 354 | 355 | 356 | 357 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 371 | 372 | 373 | 374 | -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # .github/sync-repo-settings.yaml 16 | # See https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings for app options. 17 | rebaseMergeAllowed: true 18 | squashMergeAllowed: true 19 | mergeCommitAllowed: false 20 | deleteBranchOnMerge: true 21 | branchProtectionRules: 22 | - pattern: main 23 | isAdminEnforced: false 24 | requiresStrictStatusChecks: false 25 | requiredStatusCheckContexts: 26 | # .github/workflows/test.yml with a job called "test" 27 | - "test" 28 | # .github/workflows/lint.yml with a job called "lint" 29 | - "lint" 30 | # Google bots below 31 | - "cla/google" 32 | - "snippet-bot check" 33 | - "header-check" 34 | - "conventionalcommits.org" 35 | requiredApprovingReviewCount: 1 36 | requiresCodeOwnerReviews: true 37 | permissionRules: 38 | - team: workspace-devrel-dpe 39 | permission: admin 40 | - team: workspace-devrel 41 | permission: push 42 | -------------------------------------------------------------------------------- /.github/workflows/automation.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | name: Automation 16 | on: [ push, pull_request, workflow_dispatch ] 17 | jobs: 18 | dependabot: 19 | runs-on: ubuntu-latest 20 | if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} 21 | env: 22 | PR_URL: ${{github.event.pull_request.html_url}} 23 | GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}} 24 | steps: 25 | - name: approve 26 | run: gh pr review --approve "$PR_URL" 27 | - name: merge 28 | run: gh pr merge --auto --squash --delete-branch "$PR_URL" 29 | default-branch-migration: 30 | # this job helps with migrating the default branch to main 31 | # it pushes main to master if master exists and main is the default branch 32 | # it pushes master to main if master is the default branch 33 | runs-on: ubuntu-latest 34 | if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} 35 | steps: 36 | - uses: actions/checkout@v2 37 | with: 38 | fetch-depth: 0 39 | # required otherwise GitHub blocks infinite loops in pushes originating in an action 40 | token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }} 41 | - name: Set env 42 | run: | 43 | # set DEFAULT BRANCH 44 | echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')" >> "$GITHUB_ENV"; 45 | 46 | # set HAS_MASTER_BRANCH 47 | if [ -n "$(git ls-remote --heads origin master)" ]; then 48 | echo "HAS_MASTER_BRANCH=true" >> "$GITHUB_ENV" 49 | else 50 | echo "HAS_MASTER_BRANCH=false" >> "$GITHUB_ENV" 51 | fi 52 | env: 53 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 54 | - name: configure git 55 | run: | 56 | git config --global user.name 'googleworkspace-bot' 57 | git config --global user.email 'googleworkspace-bot@google.com' 58 | - if: ${{ env.DEFAULT_BRANCH == 'main' && env.HAS_MASTER_BRANCH == 'true' }} 59 | name: Update master branch from main 60 | run: | 61 | git checkout -B master 62 | git reset --hard origin/main 63 | git push origin master 64 | - if: ${{ env.DEFAULT_BRANCH == 'master'}} 65 | name: Update main branch from master 66 | run: | 67 | git checkout -B main 68 | git reset --hard origin/master 69 | git push origin main 70 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Lint 16 | on: [push, pull_request] 17 | jobs: 18 | lint: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - run: | 23 | echo "No lint checks"; 24 | exit 1; 25 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Test 16 | on: [push, pull_request] 17 | jobs: 18 | test: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - run: | 23 | echo "No tests"; 24 | exit 1; 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Important: The content of this repository is outdated, it's now in the GitHub repository [apps-script-samples](https://github.com/googleworkspace/apps-script-samples/tree/main/solutions/attendance-chat-app).** 2 | 3 | # Attendance Bot: Hangouts Chat bot with Apps Script codelab 4 | 5 | This code sample shows how to build a Hangouts Chat bot using Google 6 | Apps Script. The bot responds to messages in a room or direct message (DM) and 7 | allows the user to set a vacation responder in Gmail or add an all-day event to 8 | their Calendar from Hangouts Chat. 9 | 10 | ## Usage 11 | 12 | You can follow [this codelab](https://codelabs.developers.google.com/codelabs/chat-apps-script/index.html) 13 | to build and test this bot. 14 | 15 | To use this bot, you must enable the Hangouts Chat API in the 16 | [Google API Console](https://console.developers.google.com/). After enabling 17 | the API, configuring the bot, and publishing it, you must add the bot to a room 18 | or DM to begin a conversation. 19 | 20 | For more information about how to publish a bot, see 21 | [Publishing bots](https://developers.google.com/hangouts/chat/how-tos/bots-publish). 22 | 23 | ## Disclaimer 24 | 25 | This is not an official product. 26 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Report a security issue 2 | 3 | To report a security issue, please use [https://g.co/vulnz](https://g.co/vulnz). We use 4 | [https://g.co/vulnz](https://g.co/vulnz) for our intake, and do coordination and disclosure here on 5 | GitHub (including using GitHub Security Advisory). The Google Security Team will 6 | respond within 5 working days of your report on [https://g.co/vulnz](https://g.co/vulnz). 7 | -------------------------------------------------------------------------------- /final/Code.gs: -------------------------------------------------------------------------------- 1 | /** 2 | * Responds to an ADDED_TO_SPACE event in Hangouts Chat. 3 | * @param {object} event the event object from Hangouts Chat 4 | * @return {object} JSON-formatted response 5 | * @see https://developers.google.com/hangouts/chat/reference/message-formats/events 6 | */ 7 | function onAddToSpace(event) { 8 | console.info(event); 9 | var message = 'Thank you for adding me to '; 10 | if (event.space.type === 'DM') { 11 | message += 'a DM, ' + event.user.displayName + '!'; 12 | } else { 13 | message += event.space.displayName; 14 | } 15 | return { text: message }; 16 | } 17 | 18 | /** 19 | * Responds to a REMOVED_FROM_SPACE event in Hangouts Chat. 20 | * @param {object} event the event object from Hangouts Chat 21 | * @see https://developers.google.com/hangouts/chat/reference/message-formats/events 22 | */ 23 | function onRemoveFromSpace(event) { 24 | console.info(event); 25 | console.log('Bot removed from ', event.space.name); 26 | } 27 | 28 | var DEFAULT_IMAGE_URL = 'https://goo.gl/bMqzYS'; 29 | var HEADER = { 30 | header: { 31 | title : 'Attendance Bot', 32 | subtitle : 'Log your vacation time', 33 | imageUrl : DEFAULT_IMAGE_URL 34 | } 35 | }; 36 | 37 | /** 38 | * Creates a card-formatted response. 39 | * @param {object} widgets the UI components to send 40 | * @return {object} JSON-formatted response 41 | */ 42 | function createCardResponse(widgets) { 43 | return { 44 | cards: [HEADER, { 45 | sections: [{ 46 | widgets: widgets 47 | }] 48 | }] 49 | }; 50 | } 51 | 52 | var REASON = { 53 | SICK: 'Out sick', 54 | OTHER: 'Out of office' 55 | }; 56 | /** 57 | * Responds to a MESSAGE event triggered in Hangouts Chat. 58 | * @param {object} event the event object from Hangouts Chat 59 | * @return {object} JSON-formatted response 60 | */ 61 | function onMessage(event) { 62 | console.info(event); 63 | var reason = REASON.OTHER; 64 | var name = event.user.displayName; 65 | var userMessage = event.message.text; 66 | 67 | // If the user said that they were 'sick', adjust the image in the 68 | // header sent in response. 69 | if (userMessage.indexOf('sick') > -1) { 70 | // Hospital material icon 71 | HEADER.header.imageUrl = 'https://goo.gl/mnZ37b'; 72 | reason = REASON.SICK; 73 | } else if (userMessage.indexOf('vacation') > -1) { 74 | // Spa material icon 75 | HEADER.header.imageUrl = 'https://goo.gl/EbgHuc'; 76 | } 77 | 78 | var widgets = [{ 79 | textParagraph: { 80 | text: 'Hello, ' + name + '.
Are you taking time off today?' 81 | } 82 | }, { 83 | buttons: [{ 84 | textButton: { 85 | text: 'Set vacation in Gmail', 86 | onClick: { 87 | action: { 88 | actionMethodName: 'turnOnAutoResponder', 89 | parameters: [{ 90 | key: 'reason', 91 | value: reason 92 | }] 93 | } 94 | } 95 | } 96 | }, { 97 | textButton: { 98 | text: 'Block out day in Calendar', 99 | onClick: { 100 | action: { 101 | actionMethodName: 'blockOutCalendar', 102 | parameters: [{ 103 | key: 'reason', 104 | value: reason 105 | }] 106 | } 107 | } 108 | } 109 | }] 110 | }]; 111 | return createCardResponse(widgets); 112 | } 113 | 114 | /** 115 | * Responds to a CARD_CLICKED event triggered in Hangouts Chat. 116 | * @param {object} event the event object from Hangouts Chat 117 | * @return {object} JSON-formatted response 118 | * @see https://developers.google.com/hangouts/chat/reference/message-formats/events 119 | */ 120 | function onCardClick(event) { 121 | console.info(event); 122 | var message = ''; 123 | var reason = event.action.parameters[0].value; 124 | if (event.action.actionMethodName == 'turnOnAutoResponder') { 125 | turnOnAutoResponder(reason); 126 | message = 'Turned on vacation settings.'; 127 | } else if (event.action.actionMethodName == 'blockOutCalendar') { 128 | blockOutCalendar(reason); 129 | message = 'Blocked out your calendar for the day.'; 130 | } else { 131 | message = "I'm sorry; I'm not sure which button you clicked."; 132 | } 133 | return { text: message }; 134 | } 135 | 136 | var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000; 137 | /** 138 | * Turns on the user's vacation response for today in Gmail. 139 | * @param {string} reason the reason for vacation, either REASON.SICK or REASON.OTHER 140 | */ 141 | function turnOnAutoResponder(reason) { 142 | var currentTime = (new Date()).getTime(); 143 | Gmail.Users.Settings.updateVacation({ 144 | enableAutoReply: true, 145 | responseSubject: reason, 146 | responseBodyHtml: "I'm out of the office today; will be back on the next business day.

Created by Attendance Bot!", 147 | restrictToContacts: true, 148 | restrictToDomain: true, 149 | startTime: currentTime, 150 | endTime: currentTime + ONE_DAY_MILLIS 151 | }, 'me'); 152 | } 153 | 154 | /** 155 | * Places an all-day meeting on the user's Calendar. 156 | * @param {string} reason the reason for vacation, either REASON.SICK or REASON.OTHER 157 | */ 158 | function blockOutCalendar(reason) { 159 | CalendarApp.createAllDayEvent(reason, new Date(), new Date(Date.now() + ONE_DAY_MILLIS)); 160 | } 161 | -------------------------------------------------------------------------------- /final/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "America/Los_Angeles", 3 | "dependencies": { 4 | "enabledAdvancedServices": [{ 5 | "userSymbol": "Gmail", 6 | "serviceId": "gmail", 7 | "version": "v1" 8 | }] 9 | }, 10 | "chat": { 11 | } 12 | } -------------------------------------------------------------------------------- /step-3/Code.gs: -------------------------------------------------------------------------------- 1 | /** 2 | * Responds to an ADDED_TO_SPACE event 3 | * in Hangouts Chat. 4 | * 5 | * @param event the event object from Hangouts Chat 6 | * @return JSON-formatted response 7 | */ 8 | function onAddToSpace(event) { 9 | console.info(event); 10 | 11 | var message = ""; 12 | 13 | if (event.space.type === "DM") { 14 | message = "Thank you for adding me to a DM, " + 15 | event.user.displayName + "!"; 16 | } else { 17 | message = "Thank you for adding me to " + 18 | event.space.displayName; 19 | } 20 | 21 | return { "text": message }; 22 | } 23 | 24 | /** 25 | * Responds to a REMOVED_FROM_SPACE event 26 | * in Hangouts Chat. 27 | * 28 | * @param event the event object from Hangouts Chat 29 | */ 30 | function onRemoveFromSpace(event) { 31 | console.info(event); 32 | console.info("Bot removed from ", event.space.name); 33 | } 34 | -------------------------------------------------------------------------------- /step-3/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "America/Los_Angeles", 3 | "dependencies": { 4 | }, 5 | "chat": {} 6 | } -------------------------------------------------------------------------------- /step-4/Code.gs: -------------------------------------------------------------------------------- 1 | /** 2 | * Responds to an ADDED_TO_SPACE event 3 | * in Hangouts Chat. 4 | * 5 | * @param event the event object from Hangouts Chat 6 | * @return JSON-formatted response 7 | */ 8 | function onAddToSpace(event) { 9 | console.info(event); 10 | 11 | var message = ""; 12 | 13 | if (event.space.type === "DM") { 14 | message = "Thank you for adding me to a DM, " + 15 | event.user.displayName + "!"; 16 | } else { 17 | message = "Thank you for adding me to " + 18 | event.space.displayName; 19 | } 20 | 21 | return { "text": message }; 22 | } 23 | 24 | /** 25 | * Responds to a REMOVED_FROM_SPACE event 26 | * in Hangouts Chat. 27 | * 28 | * @param event the event object from Hangouts Chat 29 | */ 30 | function onRemoveFromSpace(event) { 31 | console.info(event); 32 | console.info("Bot removed from ", event.space.name); 33 | } 34 | -------------------------------------------------------------------------------- /step-4/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "America/Los_Angeles", 3 | "dependencies": { 4 | }, 5 | "chat": {} 6 | } -------------------------------------------------------------------------------- /step-5/Code.gs: -------------------------------------------------------------------------------- 1 | /** 2 | * Responds to an ADDED_TO_SPACE event 3 | * in Hangouts Chat. 4 | * 5 | * @param event the event object from Hangouts Chat 6 | * @return JSON-formatted response 7 | */ 8 | function onAddToSpace(event) { 9 | console.info(event); 10 | 11 | var message = ""; 12 | 13 | if (event.space.type === "DM") { 14 | message = "Thank you for adding me to a DM, " + 15 | event.user.displayName + "!"; 16 | } else { 17 | message = "Thank you for adding me to " + 18 | event.space.displayName; 19 | } 20 | 21 | return { "text": message }; 22 | } 23 | 24 | /** 25 | * Responds to a REMOVED_FROM_SPACE event 26 | * in Hangouts Chat. 27 | * 28 | * @param event the event object from Hangouts Chat 29 | */ 30 | function onRemoveFromSpace(event) { 31 | console.info(event); 32 | console.info("Bot removed from ", event.space.name); 33 | } 34 | 35 | /** 36 | * Creates a card-formatted response. 37 | * 38 | * @param widgets the UI components to send 39 | * @return JSON-formatted response 40 | */ 41 | function createCardResponse(widgets) { 42 | return { 43 | "cards": [ 44 | header, 45 | { 46 | "sections": [{ 47 | "widgets": widgets 48 | }] 49 | }] 50 | }; 51 | } 52 | 53 | /** 54 | * Responds to a MESSAGE event triggered in Hangouts Chat. 55 | * 56 | * @param event the event object from Hangouts Chat 57 | * @return JSON-formatted response 58 | */ 59 | function onMessage(event) { 60 | var userMessage = event.message.text; 61 | 62 | var widgets = [{ 63 | "textParagraph": { 64 | "text": "You said: " + userMessage 65 | } 66 | }]; 67 | 68 | return createCardResponse(widgets); 69 | } -------------------------------------------------------------------------------- /step-5/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "America/Los_Angeles", 3 | "dependencies": { 4 | }, 5 | "chat": {} 6 | } -------------------------------------------------------------------------------- /step-6/Code.gs: -------------------------------------------------------------------------------- 1 | /** 2 | * Responds to an ADDED_TO_SPACE event 3 | * in Hangouts Chat. 4 | * 5 | * @param event the event object from Hangouts Chat 6 | * @return JSON-formatted response 7 | */ 8 | function onAddToSpace(event) { 9 | console.info(event); 10 | 11 | var message = ""; 12 | 13 | if (event.space.type === "DM") { 14 | message = "Thank you for adding me to a DM, " + 15 | event.user.displayName + "!"; 16 | } else { 17 | message = "Thank you for adding me to " + 18 | event.space.displayName; 19 | } 20 | 21 | return { "text": message }; 22 | } 23 | 24 | /** 25 | * Responds to a REMOVED_FROM_SPACE event 26 | * in Hangouts Chat. 27 | * 28 | * @param event the event object from Hangouts Chat 29 | */ 30 | function onRemoveFromSpace(event) { 31 | console.info(event); 32 | console.info("Bot removed from ", event.space.name); 33 | } 34 | 35 | var DEFAULT_IMAGE_URL = "https://goo.gl/bMqzYS"; 36 | var header = { 37 | "header": { 38 | "title" : "Attendance Bot", 39 | "subtitle" : "Log your vacation time", 40 | "imageUrl" : DEFAULT_IMAGE_URL 41 | } 42 | }; 43 | 44 | /** 45 | * Creates a card-formatted response. 46 | * 47 | * @param widgets the UI components to send 48 | * @return JSON-formatted response 49 | */ 50 | function createCardResponse(widgets) { 51 | return { 52 | "cards": [ 53 | header, 54 | { 55 | "sections": [{ 56 | "widgets": widgets 57 | }] 58 | }] 59 | }; 60 | } 61 | 62 | var REASON_SICK = "Out sick"; 63 | var REASON_OTHER = "Out of office"; 64 | 65 | /** 66 | * Responds to a MESSAGE event triggered in Hangouts Chat. 67 | * 68 | * @param event the event object from Hangouts Chat 69 | * @return JSON-formatted response 70 | */ 71 | function onMessage(event) { 72 | console.info(event); 73 | 74 | var reason = REASON_OTHER; 75 | var name = event.user.displayName; 76 | var userMessage = event.message.text; 77 | 78 | // If the user said that they were "sick", adjust the image in the 79 | // header sent in response. 80 | if (userMessage.indexOf("sick") > -1) { 81 | 82 | // Hospital material icon 83 | header.header.imageUrl = "https://goo.gl/mnZ37b"; 84 | reason = REASON_SICK; 85 | 86 | } else if (userMessage.indexOf("vacation") > -1) { 87 | 88 | // Spa material icon 89 | header.header.imageUrl = "https://goo.gl/EbgHuc"; 90 | } 91 | 92 | var widgets = [{ 93 | "textParagraph": { 94 | "text": "Hello, " + name + 95 | ".
Are you taking time off today?" 96 | } 97 | }, { 98 | "buttons": [{ 99 | "textButton": { 100 | "text": "Set vacation in Gmail", 101 | "onClick": { 102 | "action": { 103 | "actionMethodName": "turnOnAutoResponder", 104 | "parameters": [{ 105 | "key": "reason", 106 | "value": reason 107 | }] 108 | } 109 | } 110 | } 111 | }, { 112 | "textButton": { 113 | "text": "Block out day in Calendar", 114 | "onClick": { 115 | "action": { 116 | "actionMethodName": "blockOutCalendar", 117 | "parameters": [{ 118 | "key": "reason", 119 | "value": reason 120 | }] 121 | } 122 | } 123 | } 124 | }] 125 | }]; 126 | 127 | return createCardResponse(widgets); 128 | } 129 | 130 | /** 131 | * Responds to a CARD_CLICKED event triggered in Hangouts Chat. 132 | * 133 | * @param event the event object from Hangouts Chat 134 | * @return JSON-formatted response 135 | */ 136 | function onCardClick(event) { 137 | console.info(event); 138 | 139 | var message = ""; 140 | var reason = event.action.parameters[0].value; 141 | 142 | if (event.action.actionMethodName == "turnOnAutoResponder") { 143 | turnOnAutoResponder(reason); 144 | message = "Turned on vacation settings."; 145 | } else if (event.action.actionMethodName == "blockOutCalendar") { 146 | blockOutCalendar(reason); 147 | message = "Blocked out your calendar for the day."; 148 | } else { 149 | message = "I'm sorry; I'm not sure which button you clicked."; 150 | } 151 | 152 | return { "text": message }; 153 | } 154 | 155 | var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000; 156 | 157 | /** 158 | * Turns on the user's vacation response for today in Gmail. 159 | * 160 | * @param reason the reason for vacation, either REASON_SICK or REASON_OTHER 161 | */ 162 | function turnOnAutoResponder(reason) { 163 | var currentTime = (new Date()).getTime(); 164 | 165 | Gmail.Users.Settings.updateVacation({ 166 | "enableAutoReply": true, 167 | "responseSubject": reason, 168 | "responseBodyHtml": "I'm out of the office today; will be back on the next business day.

Created by Attendance Bot!", 169 | "restrictToContacts": true, 170 | "restrictToDomain": true, 171 | "startTime": currentTime, 172 | "endTime": currentTime + ONE_DAY_MILLIS 173 | }, "me"); 174 | } 175 | 176 | /** 177 | * Places an all-day meeting on the user's Calendar. 178 | * 179 | * @param reason the reason for vacation, either REASON_SICK or REASON_OTHER 180 | */ 181 | function blockOutCalendar(reason) { 182 | CalendarApp.createAllDayEvent(reason, new Date(), new Date(Date.now() + ONE_DAY_MILLIS)); 183 | } 184 | -------------------------------------------------------------------------------- /step-6/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "America/Los_Angeles", 3 | "dependencies": { 4 | "enabledAdvancedServices": [{ 5 | "userSymbol": "Gmail", 6 | "serviceId": "gmail", 7 | "version": "v1" 8 | }] 9 | }, 10 | "chat": { 11 | } 12 | } --------------------------------------------------------------------------------