Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions advanced/chat.gs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,45 @@ function listMemberships(spaceName) {
}
}
// [END chat_list_memberships]

// [START chat_search_messages]
/**
* Searches for unread messages for the caller user in all Chat spaces.
*/
function searchMessages() {
let response;
let pageToken = null;
try {
do {
response = Chat.Spaces.Messages.search(
{
filter: 'is_unread()'
},
'spaces/-',
{
pageSize: 10,
pageToken: pageToken,
}
);
if (!response.results || response.results.length === 0) {
pageToken = response.nextPageToken;
continue;
}
for (const result of response.results) {
const message = result.message;
console.log(
"**%s at %s in %s:**\n%s",
message.sender.name,
message.createTime,
message.space.name,
message.text,
);
}
pageToken = response.nextPageToken;
} while (pageToken);
} catch (err) {
// TODO (developer) - Handle exception
console.log("Failed with error %s", err.message);
}
}
// [END chat_search_messages]
40 changes: 40 additions & 0 deletions chat/advanced-service/Main.gs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
};

// Make the request
const response = Chat.Spaces.Members.create(membership, parent);

Check failure on line 47 in chat/advanced-service/Main.gs

View workflow job for this annotation

GitHub Actions / test (chat)

Cannot find name 'Chat'.

// Handle the response
console.log(response);
Expand Down Expand Up @@ -72,7 +72,7 @@
};

// Make the request
const response = Chat.Spaces.Members.create(membership, parent);

Check failure on line 75 in chat/advanced-service/Main.gs

View workflow job for this annotation

GitHub Actions / test (chat)

Cannot find name 'Chat'.

// Handle the response
console.log(response);
Expand All @@ -98,7 +98,7 @@
};

// Make the request
const response = Chat.Spaces.Members.create(membership, parent);

Check failure on line 101 in chat/advanced-service/Main.gs

View workflow job for this annotation

GitHub Actions / test (chat)

Cannot find name 'Chat'.

// Handle the response
console.log(response);
Expand Down Expand Up @@ -771,6 +771,46 @@
}
// [END chat_list_spaces_user_cred]

// [START chat_search_messages_user_cred]
/**
* This sample shows how to search messages with user credential
*
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.messages.readonly'
* referenced in the manifest file (appsscript.json).
*/
function searchMessagesUserCred() {
// Initialize request argument(s)
// TODO(developer): Replace FILTER here with an actual filter query
const filter = "FILTER";
const parent = "spaces/-";

// Iterate through the response pages using page tokens
let responsePage;
let pageToken = null;
do {
// Request response pages
responsePage = Chat.Spaces.Messages.search(
{
filter: filter,
},
parent,
{
pageSize: 10,
pageToken: pageToken,
}
);
// Handle response pages
if (responsePage.results) {
for (const result of responsePage.results) {
console.log(result);
}
}
// Update the page token to the next one
pageToken = responsePage.nextPageToken;
} while (pageToken);
}
// [END chat_search_messages_user_cred]

// [START chat_set_up_space_user_cred]
/**
* This sample shows how to set up a named space with one initial member with
Expand Down
Loading