diff --git a/gmail-sentiment-analysis/Cards.gs b/gmail-sentiment-analysis/Cards.gs index f0360318d..a520eda8c 100644 --- a/gmail-sentiment-analysis/Cards.gs +++ b/gmail-sentiment-analysis/Cards.gs @@ -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. */ @@ -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") @@ -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() diff --git a/gmail-sentiment-analysis/Gmail.gs b/gmail-sentiment-analysis/Gmail.gs index d4e6fe2b2..64ac50675 100644 --- a/gmail-sentiment-analysis/Gmail.gs +++ b/gmail-sentiment-analysis/Gmail.gs @@ -48,7 +48,7 @@ function analyzeAndLabelEmailSentiment() { const isUpset = isNegativeSentiment(emailText); if (isUpset) { - label.addToThread(thread); + thread.addLabel(label); } } } diff --git a/gmail-sentiment-analysis/Samples.gs b/gmail-sentiment-analysis/Samples.gs index b3ce18691..3c906772b 100644 --- a/gmail-sentiment-analysis/Samples.gs +++ b/gmail-sentiment-analysis/Samples.gs @@ -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. @@ -24,8 +24,8 @@ 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', }, @@ -33,8 +33,8 @@ function generateSampleEmails() { 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', }, @@ -42,12 +42,14 @@ function generateSampleEmails() { 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: `
Hello, You are late in delivery, again.
+Please contact me ASAP before I cancel our subscription.
`, }, ); - console.log("Sample email generation completed.") + console.log('Sample email generation completed.') } diff --git a/gmail-sentiment-analysis/Vertex.gs b/gmail-sentiment-analysis/Vertex.gs index 3f02fefff..7c01b7a8e 100644 --- a/gmail-sentiment-analysis/Vertex.gs +++ b/gmail-sentiment-analysis/Vertex.gs @@ -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()); diff --git a/gmail-sentiment-analysis/appsscript.json b/gmail-sentiment-analysis/appsscript.json index 0a888d217..803c363e8 100644 --- a/gmail-sentiment-analysis/appsscript.json +++ b/gmail-sentiment-analysis/appsscript.json @@ -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": {