Skip to content

Commit

Permalink
feat: add create and set up space code samples (#489)
Browse files Browse the repository at this point in the history
Co-authored-by: pierrick <[email protected]>
  • Loading branch information
PierrickVoulet and pierrick authored Oct 3, 2024
1 parent 7a8eca7 commit 0b0d728
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions chat/advanced-service/Main.gs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions chat/advanced-service/appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0b0d728

Please sign in to comment.