Skip to content

Commit ad1779c

Browse files
authored
chore: Minor updates (#517)
1 parent 6599fed commit ad1779c

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

gmail-sentiment-analysis/Cards.gs

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717

1818
/**
19-
* Builds the card to display in the sidepanel of gmail.
19+
* Builds the card to display in the side panel of gmail.
2020
* @return {CardService.Card} The card to show to the user.
2121
*/
2222

@@ -33,7 +33,16 @@ function buildCard_GmailHome(notifyOk = false) {
3333
.setText('Identify angry customers')
3434
.setOnClickAction(action)
3535
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
36-
const buttonSet = CardService.newButtonSet().addButton(button);
36+
37+
const generateSampleEmailsAction = CardService.newAction()
38+
.setFunctionName('generateSampleEmails');
39+
const generateSampleEmailsBtn = CardService.newTextButton()
40+
.setText('Generate sample emails')
41+
.setOnClickAction(generateSampleEmailsAction)
42+
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
43+
.setBackgroundColor('#34A853');
44+
45+
const buttonSet = CardService.newButtonSet().addButton(button).addButton(generateSampleEmailsBtn);
3746

3847
const section = CardService.newCardSection()
3948
.setHeader("Emails sentiment analysis")
@@ -47,7 +56,7 @@ function buildCard_GmailHome(notifyOk = false) {
4756
* This builds the card that contains the footer that informs
4857
* the user about the successful execution of the Add-on.
4958
*/
50-
if (notifyOk == true) {
59+
if (notifyOk) {
5160
const fixedFooter = CardService.newFixedFooter()
5261
.setPrimaryButton(
5362
CardService.newTextButton()

gmail-sentiment-analysis/Gmail.gs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function analyzeAndLabelEmailSentiment() {
4848
const isUpset = isNegativeSentiment(emailText);
4949

5050
if (isUpset) {
51-
label.addToThread(thread);
51+
thread.addLabel(label);
5252
}
5353
}
5454
}

gmail-sentiment-analysis/Samples.gs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
Copyright 2025 Google LLC
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
4+
Licensed under the Apache License, Version 2.0 (the 'License');
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
88
https://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
11+
distributed under the License is distributed on an 'AS IS' BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
@@ -24,30 +24,32 @@ function generateSampleEmails() {
2424
// Send emails
2525
GmailApp.sendEmail(
2626
userEmail,
27-
"Thank you for amazing service!",
28-
"Hi, I really enjoyed working with you. Thank you again!",
27+
'Thank you for amazing service!',
28+
'Hi, I really enjoyed working with you. Thank you again!',
2929
{
3030
name: 'Customer A',
3131
},
3232
);
3333

3434
GmailApp.sendEmail(
3535
userEmail,
36-
"Request for information",
37-
"Hello, I need more information on your recent product launch. Thank you.",
36+
'Request for information',
37+
'Hello, I need more information on your recent product launch. Thank you.',
3838
{
3939
name: 'Customer B',
4040
},
4141
);
4242

4343
GmailApp.sendEmail(
4444
userEmail,
45-
"Complaint!",
46-
"Hello, You are late in delivery, again. Please contact me ASAP before I cancel our subscription.",
45+
'Complaint!',
46+
'',
4747
{
4848
name: 'Customer C',
49+
htmlBody: `<p>Hello, You are late in delivery, again.</p>
50+
<p>Please contact me ASAP before I cancel our subscription.</p>`,
4951
},
5052
);
5153

52-
console.log("Sample email generation completed.")
54+
console.log('Sample email generation completed.')
5355
}

gmail-sentiment-analysis/Vertex.gs

+6-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ function processSentiment(emailText) {
6767
payload: JSON.stringify(request),
6868
}
6969

70-
const url = `https://${VERTEX_AI_LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/`
71-
+ `locations/${VERTEX_AI_LOCATION}/publishers/google/models/${MODEL_ID}:generateContent`
70+
const url =
71+
`https://${VERTEX_AI_LOCATION}-aiplatform.googleapis.com/v1/` +
72+
`projects/${PROJECT_ID}/` +
73+
`locations/${VERTEX_AI_LOCATION}/` +
74+
`publishers/google/` +
75+
`models/${MODEL_ID}:generateContent`;
7276

7377
const response = UrlFetchApp.fetch(url, fetchOptions);
7478
const payload = JSON.parse(response.getContentText());

gmail-sentiment-analysis/appsscript.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"timeZone": "America/Los_Angeles",
33
"oauthScopes": [
4-
"https://www.googleapis.com/auth/script.external_request",
54
"https://www.googleapis.com/auth/cloud-platform",
6-
"https://www.googleapis.com/auth/script.locale",
7-
"https://www.googleapis.com/auth/userinfo.email",
85
"https://www.googleapis.com/auth/gmail.addons.execute",
96
"https://www.googleapis.com/auth/gmail.labels",
10-
"https://www.googleapis.com/auth/gmail.modify"
7+
"https://www.googleapis.com/auth/gmail.modify",
8+
"https://www.googleapis.com/auth/script.external_request",
9+
"https://www.googleapis.com/auth/script.locale",
10+
"https://www.googleapis.com/auth/userinfo.email"
1111
],
1212
"addOns": {
1313
"common": {

0 commit comments

Comments
 (0)