Skip to content

Commit

Permalink
feat: Add Google Chat API quickstart (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: pierrick <[email protected]>
  • Loading branch information
PierrickVoulet and pierrick authored Jul 30, 2024
1 parent 9808fee commit be16446
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
46 changes: 46 additions & 0 deletions chat/quickstart/Code.gs
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]
11 changes: 11 additions & 0 deletions chat/quickstart/README.md
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.
16 changes: 16 additions & 0 deletions chat/quickstart/appsscript.json
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"
}]
}
}

0 comments on commit be16446

Please sign in to comment.