Skip to content

Commit ac52039

Browse files
authored
Merge branch 'main' into jules-code-cleanup
2 parents 4d43c8a + 34d0e2d commit ac52039

File tree

163 files changed

+31268
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+31268
-426
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
moment.gs
1+
moment.gs
2+
wasm/**

.github/workflows/publish.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ on:
1717
workflow_dispatch:
1818
push:
1919
branches:
20-
- master
20+
- main
2121
jobs:
2222
publish:
2323
concurrency:
2424
group: ${{ github.head_ref || github.ref }}
2525
cancel-in-progress: false
26-
runs-on: ubuntu-20.04
26+
runs-on: ubuntu-24.04
2727
steps:
2828
- uses: actions/[email protected]
2929
with:
@@ -38,6 +38,6 @@ jobs:
3838
CLASP_CREDENTIALS: ${{secrets.CLASP_CREDENTIALS}}
3939
- uses: actions/setup-node@v3
4040
with:
41-
node-version: '14'
41+
node-version: '20'
4242
- run: npm install -g @google/clasp
4343
- run: ./.github/scripts/clasp_push.sh ${{ steps.changed-files.outputs.all_changed_files }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.DS_Store
22
node_modules
3-
.gradle
3+
.gradle
4+
**/dist
5+
**/node_modules
6+
**/target

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Codelab tutorials combine detailed explanation, coding exercises, and documented
135135
- [BigQuery + Sheets + Slides](http://g.co/codelabs/bigquery-sheets-slides)
136136
- [Docs Add-on + Cloud Natural Language API](http://g.co/codelabs/nlp-docs)
137137
- [Gmail Add-ons](http://g.co/codelabs/gmail-add-ons)
138-
- [Hangouts Chat Bots](http://g.co/codelabs/chat-apps-script)
138+
- [Google Chat Apps](https://developers.google.com/codelabs/chat-apps-script)
139139

140140
## Clone using the `clasp` command-line tool
141141

advanced/calendar.gs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function listNext10Events() {
117117
// All-day event.
118118
const start = new Date(event.start.date);
119119
console.log('%s (%s)', event.summary, start.toLocaleDateString());
120-
return;
120+
continue;
121121
}
122122
const start = new Date(event.start.dateTime);
123123
console.log('%s (%s)', event.summary, start.toLocaleString());

advanced/chat.gs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* Copyright Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START chat_post_message_with_user_credentials]
18+
/**
19+
* Posts a new message to the specified space on behalf of the user.
20+
* @param {string} spaceName The resource name of the space.
21+
*/
22+
function postMessageWithUserCredentials(spaceName) {
23+
try {
24+
const message = {'text': 'Hello world!'};
25+
Chat.Spaces.Messages.create(message, spaceName);
26+
} catch (err) {
27+
// TODO (developer) - Handle exception
28+
console.log('Failed to create message with error %s', err.message);
29+
}
30+
}
31+
// [END chat_post_message_with_user_credentials]
32+
33+
// [START chat_post_message_with_app_credentials]
34+
/**
35+
* Posts a new message to the specified space on behalf of the app.
36+
* @param {string} spaceName The resource name of the space.
37+
*/
38+
function postMessageWithAppCredentials(spaceName) {
39+
try {
40+
// See https://developers.google.com/chat/api/guides/auth/service-accounts
41+
// for details on how to obtain a service account OAuth token.
42+
const appToken = getToken_();
43+
const message = {'text': 'Hello world!'};
44+
Chat.Spaces.Messages.create(
45+
message,
46+
spaceName,
47+
{},
48+
// Authenticate with the service account token.
49+
{'Authorization': 'Bearer ' + appToken});
50+
} catch (err) {
51+
// TODO (developer) - Handle exception
52+
console.log('Failed to create message with error %s', err.message);
53+
}
54+
}
55+
// [END chat_post_message_with_app_credentials]
56+
57+
// [START chat_get_space]
58+
/**
59+
* Gets information about a Chat space.
60+
* @param {string} spaceName The resource name of the space.
61+
*/
62+
function getSpace(spaceName) {
63+
try {
64+
const space = Chat.Spaces.get(spaceName);
65+
console.log('Space display name: %s', space.displayName);
66+
console.log('Space type: %s', space.spaceType);
67+
} catch (err) {
68+
// TODO (developer) - Handle exception
69+
console.log('Failed to get space with error %s', err.message);
70+
}
71+
}
72+
// [END chat_get_space]
73+
74+
// [START chat_create_space]
75+
/**
76+
* Creates a new Chat space.
77+
*/
78+
function createSpace() {
79+
try {
80+
const space = {'displayName': 'New Space', 'spaceType': 'SPACE'};
81+
Chat.Spaces.create(space);
82+
} catch (err) {
83+
// TODO (developer) - Handle exception
84+
console.log('Failed to create space with error %s', err.message);
85+
}
86+
}
87+
// [END chat_create_space]
88+
89+
// [START chat_list_memberships]
90+
/**
91+
* Lists all the members of a Chat space.
92+
* @param {string} spaceName The resource name of the space.
93+
*/
94+
function listMemberships(spaceName) {
95+
let response;
96+
let pageToken = null;
97+
try {
98+
do {
99+
response = Chat.Spaces.Members.list(spaceName, {
100+
pageSize: 10,
101+
pageToken: pageToken
102+
});
103+
if (!response.memberships || response.memberships.length === 0) {
104+
pageToken = response.nextPageToken;
105+
continue;
106+
}
107+
response.memberships.forEach((membership) => console.log(
108+
'Member resource name: %s (type: %s)',
109+
membership.name,
110+
membership.member.type));
111+
pageToken = response.nextPageToken;
112+
} while (pageToken);
113+
} catch (err) {
114+
// TODO (developer) - Handle exception
115+
console.log('Failed with error %s', err.message);
116+
}
117+
}
118+
// [END chat_list_memberships]

advanced/displayvideo.gs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// [START apps_script_dv360_list_partners]
17+
/**
18+
* Logs all of the partners available in the account.
19+
*/
20+
function listPartners() {
21+
// Retrieve the list of available partners
22+
try {
23+
const partners = DisplayVideo.Partners.list();
24+
25+
if (partners.partners) {
26+
// Print out the ID and name of each
27+
for (let i = 0; i < partners.partners.length; i++) {
28+
const partner = partners.partners[i];
29+
console.log('Found partner with ID %s and name "%s".',
30+
partner.partnerId, partner.displayName);
31+
}
32+
}
33+
} catch (e) {
34+
// TODO (Developer) - Handle exception
35+
console.log('Failed with error: %s', e.error);
36+
}
37+
}
38+
// [END apps_script_dv360_list_partners]
39+
40+
// [START apps_script_dv360_list_active_campaigns]
41+
/**
42+
* Logs names and ID's of all active campaigns.
43+
* Note the use of paging tokens to retrieve the whole list.
44+
*/
45+
function listActiveCampaigns() {
46+
const advertiserId = '1234567'; // Replace with your advertiser ID.
47+
let result;
48+
let pageToken;
49+
try {
50+
do {
51+
result = DisplayVideo.Advertisers.Campaigns.list(advertiserId, {
52+
'filter': 'entityStatus="ENTITY_STATUS_ACTIVE"',
53+
'pageToken': pageToken
54+
});
55+
if (result.campaigns) {
56+
for (let i = 0; i < result.campaigns.length; i++) {
57+
const campaign = result.campaigns[i];
58+
console.log('Found campaign with ID %s and name "%s".',
59+
campaign.campaignId, campaign.displayName);
60+
}
61+
}
62+
pageToken = result.nextPageToken;
63+
} while (pageToken);
64+
} catch (e) {
65+
// TODO (Developer) - Handle exception
66+
console.log('Failed with error: %s', e.error);
67+
}
68+
}
69+
// [END apps_script_dv360_list_active_campaigns]
70+
71+
// [START apps_script_dv360_update_line_item_name]
72+
/**
73+
* Updates the display name of a line item
74+
*/
75+
function updateLineItemName() {
76+
const advertiserId = '1234567'; // Replace with your advertiser ID.
77+
const lineItemId = '123456789'; //Replace with your line item ID.
78+
const updateMask = "displayName";
79+
80+
const lineItemDef = {displayName: 'New Line Item Name (updated from Apps Script!)'};
81+
82+
try {
83+
const lineItem = DisplayVideo.Advertisers.LineItems
84+
.patch(lineItemDef, advertiserId, lineItemId, {updateMask:updateMask});
85+
86+
87+
} catch (e) {
88+
// TODO (Developer) - Handle exception
89+
console.log('Failed with error: %s', e.error);
90+
}
91+
}
92+
// [END apps_script_dv360_update_line_item_name]

advanced/docs.gs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ function findAndReplace(documentId, findTextToReplacementMap) {
4545
const requests = [];
4646
for (const findText in findTextToReplacementMap) {
4747
const replaceText = findTextToReplacementMap[findText];
48+
// One option for replacing all text is to specify all tab IDs.
49+
const request = {
50+
replaceAllText: {
51+
containsText: {
52+
text: findText,
53+
matchCase: true
54+
},
55+
replaceText: replaceText,
56+
tabsCriteria: {
57+
tabIds: [TAB_ID_1, TAB_ID_2, TAB_ID_3],
58+
}
59+
}
60+
};
61+
// Another option is to omit TabsCriteria if you are replacing across all tabs.
4862
const request = {
4963
replaceAllText: {
5064
containsText: {
@@ -73,8 +87,8 @@ function findAndReplace(documentId, findTextToReplacementMap) {
7387

7488
// [START docs_insert_and_style_text]
7589
/**
76-
* Insert text at the beginning of the document and then style the inserted
77-
* text.
90+
* Insert text at the beginning of the first tab in the document and then style
91+
* the inserted text.
7892
* @param {string} documentId The document the text is inserted into.
7993
* @param {string} text The text to insert into the document.
8094
* @return {Object} replies
@@ -84,7 +98,10 @@ function insertAndStyleText(documentId, text) {
8498
const requests = [{
8599
insertText: {
86100
location: {
87-
index: 1
101+
index: 1,
102+
// A tab can be specified using its ID. When omitted, the request is
103+
// applied to the first tab.
104+
// tabId: TAB_ID
88105
},
89106
text: text
90107
}
@@ -119,16 +136,17 @@ function insertAndStyleText(documentId, text) {
119136

120137
// [START docs_read_first_paragraph]
121138
/**
122-
* Read the first paragraph of the body of a document.
139+
* Read the first paragraph of the first tab in a document.
123140
* @param {string} documentId The ID of the document to read.
124141
* @return {Object} paragraphText
125142
* @see https://developers.google.com/docs/api/reference/rest/v1/documents/get
126143
*/
127144
function readFirstParagraph(documentId) {
128145
try {
129146
// Get the document using document ID
130-
const document = Docs.Documents.get(documentId);
131-
const bodyElements = document.body.content;
147+
const document = Docs.Documents.get(documentId, {'includeTabsContent': true});
148+
const firstTab = document.tabs[0];
149+
const bodyElements = firstTab.documentTab.body.content;
132150
for (let i = 0; i < bodyElements.length; i++) {
133151
const structuralElement = bodyElements[i];
134152
// Print the first paragraph text present in document

0 commit comments

Comments
 (0)