Skip to content

Commit be16446

Browse files
PierrickVouletpierrick
and
pierrick
authored
feat: Add Google Chat API quickstart (#475)
Co-authored-by: pierrick <[email protected]>
1 parent 9808fee commit be16446

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

chat/quickstart/Code.gs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START chat_quickstart]
18+
/**
19+
* This quickstart sample shows how to list spaces with user credential
20+
*
21+
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.readonly'
22+
* referenced in the manifest file (appsscript.json).
23+
*/
24+
function listSpaces() {
25+
// Initialize request argument(s)
26+
// Filter spaces by space type (SPACE or GROUP_CHAT or DIRECT_MESSAGE)
27+
const filter = 'space_type = "SPACE"';
28+
29+
// Iterate through the response pages using page tokens
30+
let responsePage;
31+
let pageToken = null;
32+
do {
33+
// Request response pages
34+
responsePage = Chat.Spaces.list({
35+
filter: filter,
36+
pageToken: pageToken
37+
});
38+
// Handle response pages
39+
if (responsePage.spaces) {
40+
responsePage.spaces.forEach((space) => console.log(space));
41+
}
42+
// Update the page token to the next one
43+
pageToken = responsePage.nextPageToken;
44+
} while (pageToken);
45+
}
46+
// [END chat_quickstart]

chat/quickstart/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Google Chat Apps Script Quickstart
2+
3+
Complete the steps described in the [quickstart instructions](
4+
https://developers.google.com/workspace/chat/api/guides/quickstart/apps-script),
5+
and in about five minutes you'll have a simple Apps Script application
6+
that makes requests to the Google Chat API.
7+
8+
## Run
9+
10+
After following the quickstart setup instructions, execute the function `listSpaces`
11+
from the Apps Script console.

chat/quickstart/appsscript.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"timeZone": "America/New_York",
3+
"exceptionLogging": "STACKDRIVER",
4+
"runtimeVersion": "V8",
5+
"oauthScopes": [
6+
"https://www.googleapis.com/auth/chat.spaces.readonly"
7+
],
8+
"chat": {},
9+
"dependencies": {
10+
"enabledAdvancedServices": [{
11+
"userSymbol": "Chat",
12+
"version": "v1",
13+
"serviceId": "chat"
14+
}]
15+
}
16+
}

0 commit comments

Comments
 (0)