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
15 changes: 12 additions & 3 deletions gmail-sentiment-analysis/Cards.gs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.


/**
* Builds the card to display in the sidepanel of gmail.
* Builds the card to display in the side panel of gmail.
* @return {CardService.Card} The card to show to the user.
*/

Expand All @@ -33,7 +33,16 @@ function buildCard_GmailHome(notifyOk = false) {
.setText('Identify angry customers')
.setOnClickAction(action)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
const buttonSet = CardService.newButtonSet().addButton(button);

const generateSampleEmailsAction = CardService.newAction()
.setFunctionName('generateSampleEmails');
const generateSampleEmailsBtn = CardService.newTextButton()
.setText('Generate sample emails')
.setOnClickAction(generateSampleEmailsAction)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setBackgroundColor('#34A853');

const buttonSet = CardService.newButtonSet().addButton(button).addButton(generateSampleEmailsBtn);

const section = CardService.newCardSection()
.setHeader("Emails sentiment analysis")
Expand All @@ -47,7 +56,7 @@ function buildCard_GmailHome(notifyOk = false) {
* This builds the card that contains the footer that informs
* the user about the successful execution of the Add-on.
*/
if (notifyOk == true) {
if (notifyOk) {
const fixedFooter = CardService.newFixedFooter()
.setPrimaryButton(
CardService.newTextButton()
Expand Down
2 changes: 1 addition & 1 deletion gmail-sentiment-analysis/Gmail.gs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function analyzeAndLabelEmailSentiment() {
const isUpset = isNegativeSentiment(emailText);

if (isUpset) {
label.addToThread(thread);
thread.addLabel(label);
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions gmail-sentiment-analysis/Samples.gs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Expand All @@ -24,30 +24,32 @@ function generateSampleEmails() {
// Send emails
GmailApp.sendEmail(
userEmail,
"Thank you for amazing service!",
"Hi, I really enjoyed working with you. Thank you again!",
'Thank you for amazing service!',
'Hi, I really enjoyed working with you. Thank you again!',
{
name: 'Customer A',
},
);

GmailApp.sendEmail(
userEmail,
"Request for information",
"Hello, I need more information on your recent product launch. Thank you.",
'Request for information',
'Hello, I need more information on your recent product launch. Thank you.',
{
name: 'Customer B',
},
);

GmailApp.sendEmail(
userEmail,
"Complaint!",
"Hello, You are late in delivery, again. Please contact me ASAP before I cancel our subscription.",
'Complaint!',
'',
{
name: 'Customer C',
htmlBody: `<p>Hello, You are late in delivery, again.</p>
<p>Please contact me ASAP before I cancel our subscription.</p>`,
},
);

console.log("Sample email generation completed.")
console.log('Sample email generation completed.')
}
8 changes: 6 additions & 2 deletions gmail-sentiment-analysis/Vertex.gs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ function processSentiment(emailText) {
payload: JSON.stringify(request),
}

const url = `https://${VERTEX_AI_LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/`
+ `locations/${VERTEX_AI_LOCATION}/publishers/google/models/${MODEL_ID}:generateContent`
const url =
`https://${VERTEX_AI_LOCATION}-aiplatform.googleapis.com/v1/` +
`projects/${PROJECT_ID}/` +
`locations/${VERTEX_AI_LOCATION}/` +
`publishers/google/` +
`models/${MODEL_ID}:generateContent`;

const response = UrlFetchApp.fetch(url, fetchOptions);
const payload = JSON.parse(response.getContentText());
Expand Down
8 changes: 4 additions & 4 deletions gmail-sentiment-analysis/appsscript.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"timeZone": "America/Los_Angeles",
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.labels",
"https://www.googleapis.com/auth/gmail.modify"
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/userinfo.email"
],
"addOns": {
"common": {
Expand Down
Loading