From 838375a627f014511ff5b22ea7ff05ef9639d7a0 Mon Sep 17 00:00:00 2001 From: pierrick Date: Thu, 3 Oct 2024 01:58:37 +0000 Subject: [PATCH] feat: add create and set up space code samples --- chat/advanced-service/Main.gs | 55 +++++++++++++++++++++++++++ chat/advanced-service/appsscript.json | 1 + 2 files changed, 56 insertions(+) diff --git a/chat/advanced-service/Main.gs b/chat/advanced-service/Main.gs index f9f7876d0..c9c57a009 100644 --- a/chat/advanced-service/Main.gs +++ b/chat/advanced-service/Main.gs @@ -345,6 +345,29 @@ function createMessageUserCredThreadName() { } // [END chat_create_message_user_cred_thread_name] +// [START chat_create_space_user_cred] +/** + * This sample shows how to create space with user credential + * + * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.create' + * referenced in the manifest file (appsscript.json). + */ +function createSpaceUserCred() { + // Initialize request argument(s) + const space = { + spaceType: 'SPACE', + // TODO(developer): Replace DISPLAY_NAME here + displayName: 'DISPLAY_NAME' + }; + + // Make the request + const response = Chat.Spaces.create(space); + + // Handle the response + console.log(response); +} +// [END chat_create_space_user_cred] + // [START chat_delete_message_app_cred] /** * This sample shows how to delete a message with app credential @@ -674,6 +697,38 @@ function listSpacesUserCred() { } // [END chat_list_spaces_user_cred] +// [START chat_set_up_space_user_cred] +/** + * This sample shows how to set up a named space with one initial member with + * user credential. + * + * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.create' + * referenced in the manifest file (appsscript.json). + */ +function setUpSpaceUserCred() { + // Initialize request argument(s) + const space = { + spaceType: 'SPACE', + // TODO(developer): Replace DISPLAY_NAME here + displayName: 'DISPLAY_NAME' + }; + const memberships = [{ + member: { + // TODO(developer): Replace USER_NAME here + name: 'users/USER_NAME', + // User type for the membership + type: 'HUMAN' + } + }]; + + // Make the request + const response = Chat.Spaces.setup({ space: space, memberships: memberships }); + + // Handle the response + console.log(response); +} +// [END chat_set_up_space_user_cred] + // [START chat_update_message_app_cred] /** * This sample shows how to update a message with app credential diff --git a/chat/advanced-service/appsscript.json b/chat/advanced-service/appsscript.json index 4fbe0a6f4..7f1d4d24f 100644 --- a/chat/advanced-service/appsscript.json +++ b/chat/advanced-service/appsscript.json @@ -4,6 +4,7 @@ "runtimeVersion": "V8", "oauthScopes": [ "https://www.googleapis.com/auth/chat.spaces", + "https://www.googleapis.com/auth/chat.spaces.create", "https://www.googleapis.com/auth/chat.spaces.readonly", "https://www.googleapis.com/auth/chat.memberships", "https://www.googleapis.com/auth/chat.memberships.app",