Skip to content

Commit 0b0d728

Browse files
PierrickVouletpierrick
andauthored
feat: add create and set up space code samples (googleworkspace#489)
Co-authored-by: pierrick <[email protected]>
1 parent 7a8eca7 commit 0b0d728

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

chat/advanced-service/Main.gs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,29 @@ function createMessageUserCredThreadName() {
345345
}
346346
// [END chat_create_message_user_cred_thread_name]
347347

348+
// [START chat_create_space_user_cred]
349+
/**
350+
* This sample shows how to create space with user credential
351+
*
352+
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.create'
353+
* referenced in the manifest file (appsscript.json).
354+
*/
355+
function createSpaceUserCred() {
356+
// Initialize request argument(s)
357+
const space = {
358+
spaceType: 'SPACE',
359+
// TODO(developer): Replace DISPLAY_NAME here
360+
displayName: 'DISPLAY_NAME'
361+
};
362+
363+
// Make the request
364+
const response = Chat.Spaces.create(space);
365+
366+
// Handle the response
367+
console.log(response);
368+
}
369+
// [END chat_create_space_user_cred]
370+
348371
// [START chat_delete_message_app_cred]
349372
/**
350373
* This sample shows how to delete a message with app credential
@@ -674,6 +697,38 @@ function listSpacesUserCred() {
674697
}
675698
// [END chat_list_spaces_user_cred]
676699

700+
// [START chat_set_up_space_user_cred]
701+
/**
702+
* This sample shows how to set up a named space with one initial member with
703+
* user credential.
704+
*
705+
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.create'
706+
* referenced in the manifest file (appsscript.json).
707+
*/
708+
function setUpSpaceUserCred() {
709+
// Initialize request argument(s)
710+
const space = {
711+
spaceType: 'SPACE',
712+
// TODO(developer): Replace DISPLAY_NAME here
713+
displayName: 'DISPLAY_NAME'
714+
};
715+
const memberships = [{
716+
member: {
717+
// TODO(developer): Replace USER_NAME here
718+
name: 'users/USER_NAME',
719+
// User type for the membership
720+
type: 'HUMAN'
721+
}
722+
}];
723+
724+
// Make the request
725+
const response = Chat.Spaces.setup({ space: space, memberships: memberships });
726+
727+
// Handle the response
728+
console.log(response);
729+
}
730+
// [END chat_set_up_space_user_cred]
731+
677732
// [START chat_update_message_app_cred]
678733
/**
679734
* This sample shows how to update a message with app credential

chat/advanced-service/appsscript.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"runtimeVersion": "V8",
55
"oauthScopes": [
66
"https://www.googleapis.com/auth/chat.spaces",
7+
"https://www.googleapis.com/auth/chat.spaces.create",
78
"https://www.googleapis.com/auth/chat.spaces.readonly",
89
"https://www.googleapis.com/auth/chat.memberships",
910
"https://www.googleapis.com/auth/chat.memberships.app",

0 commit comments

Comments
 (0)