-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Google Chat API quickstart (#475)
Co-authored-by: pierrick <[email protected]>
- Loading branch information
1 parent
9808fee
commit be16446
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// [START chat_quickstart] | ||
/** | ||
* This quickstart sample shows how to list spaces with user credential | ||
* | ||
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.readonly' | ||
* referenced in the manifest file (appsscript.json). | ||
*/ | ||
function listSpaces() { | ||
// Initialize request argument(s) | ||
// Filter spaces by space type (SPACE or GROUP_CHAT or DIRECT_MESSAGE) | ||
const filter = 'space_type = "SPACE"'; | ||
|
||
// Iterate through the response pages using page tokens | ||
let responsePage; | ||
let pageToken = null; | ||
do { | ||
// Request response pages | ||
responsePage = Chat.Spaces.list({ | ||
filter: filter, | ||
pageToken: pageToken | ||
}); | ||
// Handle response pages | ||
if (responsePage.spaces) { | ||
responsePage.spaces.forEach((space) => console.log(space)); | ||
} | ||
// Update the page token to the next one | ||
pageToken = responsePage.nextPageToken; | ||
} while (pageToken); | ||
} | ||
// [END chat_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Google Chat Apps Script Quickstart | ||
|
||
Complete the steps described in the [quickstart instructions]( | ||
https://developers.google.com/workspace/chat/api/guides/quickstart/apps-script), | ||
and in about five minutes you'll have a simple Apps Script application | ||
that makes requests to the Google Chat API. | ||
|
||
## Run | ||
|
||
After following the quickstart setup instructions, execute the function `listSpaces` | ||
from the Apps Script console. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"timeZone": "America/New_York", | ||
"exceptionLogging": "STACKDRIVER", | ||
"runtimeVersion": "V8", | ||
"oauthScopes": [ | ||
"https://www.googleapis.com/auth/chat.spaces.readonly" | ||
], | ||
"chat": {}, | ||
"dependencies": { | ||
"enabledAdvancedServices": [{ | ||
"userSymbol": "Chat", | ||
"version": "v1", | ||
"serviceId": "chat" | ||
}] | ||
} | ||
} |