Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Minor updates #519

Merged
merged 1 commit into from
Jan 23, 2025
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
13 changes: 8 additions & 5 deletions gmail-sentiment-analysis/Cards.gs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/


/**
* Builds the card to display in the side panel of gmail.
* @return {CardService.Card} The card to show to the user.
Expand All @@ -28,22 +27,26 @@ function buildHomepageCard() {
.setImageStyle(CardService.ImageStyle.CIRCLE)
.setTitle("Analyze your Gmail");

const analyzeSentimentAction = CardService.newAction().setFunctionName('analyzeSentiment');
const analyzeSentimentAction = CardService.newAction()
.setFunctionName('analyzeSentiment');
const analyzeSentimentBtn = CardService.newTextButton()
.setText('Analyze emails')
.setOnClickAction(analyzeSentimentAction)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setBackgroundColor('#FF0000');

const generateSampleEmailAction = CardService.newAction().setFunctionName('generateSampleEmails');
const generateSampleEmailAction = CardService.newAction()
.setFunctionName('generateSampleEmails');

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

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

const section = CardService.newCardSection()
.addWidget(buttonSet);
Expand All @@ -62,4 +65,4 @@ function buildNotificationResponse(notificationText) {
.setNotification(notification);

return actionResponse.build();
}
}
2 changes: 1 addition & 1 deletion gmail-sentiment-analysis/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ limitations under the License.
*/
function onHomepageTrigger(e) {
return buildHomepageCard();
}
}
2 changes: 1 addition & 1 deletion gmail-sentiment-analysis/Gmail.gs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ function generateSampleEmails() {
);

return buildNotificationResponse("Successfully generated sample emails");
}
}
21 changes: 7 additions & 14 deletions gmail-sentiment-analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ identify potentially sensitive emails.
* **Dedicated Time:** Set aside uninterrupted time.
* **Incognito/Private Window:** **Important:** Use an incognito or private browsing window to prevent conflicts with your personal accounts.

## Lab Steps
## Steps

### Task 1: Accessing Your Lab Environment

1. Click **Start lab** (in your [Qwiklabs environment](https://explore.qwiklabs.com/classrooms/16701)). This generates temporary credentials.
2. Open the provided **Gmail URL** in your incognito window.
3. Enter the provided **Username** and **Password**.
4. Accept terms and conditions.
5. Click **Get started** in Gmail and close any informational windows.

### Task 2: Set up Cloud Console
### Set up Cloud Console

1. Open the provided **Cloud Console URL** in your incognito window.
2. Check **I agree** and click **AGREE AND CONTINUE**.
Expand All @@ -42,7 +35,7 @@ identify potentially sensitive emails.
3. Click **Enable**.


### Task 3: Set Up the Apps Script Project
### Set Up the Apps Script Project

1. Open the provided **Apps Script link** in a new incognito tab.
2. Click **New project**.
Expand All @@ -60,7 +53,7 @@ identify potentially sensitive emails.
14. Return to the Apps Script tab and set the project.


### Task 4: Make a copy of the Apps Script project
### Make a copy of the Apps Script project

1. Make a copy of this
[Apps Script project](https://script.google.com/corp/home/projects/1Z2gfvr0oYn68ppDtQbv0qIuKKVWhvwOTr-gCE0GFKVjNk8NDlpfJAGAr).
Expand All @@ -69,13 +62,13 @@ identify potentially sensitive emails.
1. Click **Save**.


### Task 5: Deploy the Add-on
### Deploy the Add-on

1. Click **Deploy > Test deployments**.
2. Confirm **Gmail** is listed under Application(s) and click **Install**.
3. Click **Done**.

### Task 6: Verify Installation
### Verify Installation

Refresh the Gmail tab. You should see a new add-on icon in the right side panel.

Expand All @@ -85,7 +78,7 @@ Refresh the Gmail tab. You should see a new add-on icon in the right side panel.
* Uninstall and reinstall the add-on from the Test deployments window if it's still missing.


### Task 7: Run the Add-on
### Run the Add-on

1. **Open the Add-on:** Click the add-on icon in the Gmail side panel.
2. **Authorize the Add-on:** Click **Authorize access**. Select your email and click **Allow** in the consent screen.
Expand Down
10 changes: 7 additions & 3 deletions gmail-sentiment-analysis/Vertex.gs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ 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());
const text = JSON.parse(payload.candidates[0].content.parts[0].text);

return text.response;
}
}
10 changes: 5 additions & 5 deletions gmail-sentiment-analysis/appsscript.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"timeZone": "America/Toronto",
"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 All @@ -24,4 +24,4 @@
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
}
Loading