Skip to content

Commit

Permalink
Updating chat.gs with sqrrrl's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danielatgoogle authored Oct 26, 2023
1 parent 06aebd2 commit 7d7befa
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions advanced/chat.gs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
function postMessageWithUserCredentials(spaceName) {
try {
const message = { 'text': 'Hello world!' };
const message = {'text': 'Hello world!'};
Chat.Spaces.Messages.create(message, spaceName);
} catch (err) {
// TODO (developer) - Handle exception
Expand All @@ -40,13 +40,13 @@ function postMessageWithAppCredentials(spaceName) {
// See https://developers.google.com/chat/api/guides/auth/service-accounts
// for details on how to obtain a service account OAuth token.
const appToken = getToken_();
const message = { 'text': 'Hello world!' };
const message = {'text': 'Hello world!'};
Chat.Spaces.Messages.create(
message,
spaceName,
{},
// Authenticate with the service account token.
{ 'Authorization': 'Bearer ' + appToken });
message,
spaceName,
{},
// Authenticate with the service account token.
{'Authorization': 'Bearer ' + appToken});
} catch (err) {
// TODO (developer) - Handle exception
console.log('Failed to create message with error %s', err.message);
Expand Down Expand Up @@ -77,7 +77,7 @@ function getSpace(spaceName) {
*/
function createSpace() {
try {
const space = { 'displayName': 'New Space', 'spaceType': 'SPACE' };
const space = {'displayName': 'New Space', 'spaceType': 'SPACE'};
Chat.Spaces.create(space);
} catch (err) {
// TODO (developer) - Handle exception
Expand All @@ -94,28 +94,23 @@ function createSpace() {
function listMemberships(spaceName) {
let response;
let pageToken = null;
do {
try {
response = Chat.Spaces.Members.list(spaceName, {
pageSize: 10,
pageToken: pageToken
});
if (!response.memberships || response.memberships.length === 0) {
console.log('No memberships found.');
return;
}
for (let i = 0; i < response.memberships.length; i++) {
const membership = response.memberships[i];
console.log(
'Member resource name: %s (type: %s)',
membership.name,
membership.member.type);
}
try {
response = Chat.Spaces.Members.list(spaceName, {
pageSize: 10,
pageToken: pageToken
});
if (!response.memberships || response.memberships.length === 0) {
pageToken = response.nextPageToken;
} catch (err) {
// TODO (developer) - Handle exception
console.log('Failed with error %s', err.message);
continue;
}
} while (pageToken);
response.memberships.forEach(member => console.log(
'Member resource name: %s (type: %s)',
membership.name,
membership.member.type);
pageToken = response.nextPageToken;
} catch (err) {
// TODO (developer) - Handle exception
console.log('Failed with error %s', err.message);
}
}
// [END chat_list_memberships]

0 comments on commit 7d7befa

Please sign in to comment.