Sure! Here is a README file that explains the usage and functionality of the provided Google Apps Script code:
This project consists of a Google Apps Script that enhances the functionality of a Google Sheet. The script performs three main functions:
- Restricts editing based on user roles.
- Generates summaries for texts in the sheet using the Gemini API.
- Sends the generated summaries to specified email addresses.
- Edit Restriction: Ensures only the respective user or an admin can edit certain rows.
- Text Summarization: Uses the Gemini API to generate summaries for texts in the sheet.
- Email Summaries: Sends the generated summaries to specified email addresses.
The project consists of three main script files:
onEdit.js- Handles the edit restrictions.generateSummaries.js- Manages text summarization.sendSummariesByEmail.js- Sends the generated summaries via email.
-
Create a Google Sheet:
- Create a new Google Sheet.
- Add two sheets within the Google Sheet:
StudentandAdmins.
-
Configure the Sheets:
- Student Sheet: The first column (A) should contain the student email addresses, the second column (B) should have the text entries, and the third column (C) will store the generated summaries.
- Admins Sheet: The first column (A) should contain the email addresses of the admin users.
-
Open the Script Editor:
- In your Google Sheet, navigate to
Extensions>Apps Script.
- In your Google Sheet, navigate to
-
Create the Script Files:
- Create the three script files (
onEdit.js,generateSummaries.js, andsendSummariesByEmail.js) in the Apps Script editor.
- Create the three script files (
-
Copy the Provided Code:
- Copy the provided code into their respective script files in the Apps Script editor.
-
Save the Scripts:
- Save each script file.
-
Set Up Triggers:
- Set up an
onEdittrigger for theonEditfunction:- Go to
Triggers>Add Trigger. - Choose
onEditfrom the function dropdown. - Choose
From spreadsheetas the event source. - Choose
On editas the event type.
- Go to
- Set up an
The onEdit function checks if the user attempting to edit a row is either the owner of the email in the first column or an admin. If the user is not authorized, the change is reverted and a message is shown.
The generateSummaries function fetches text entries from column B of the Student sheet, sends them to the Gemini API for summarization, and writes the summaries to column C.
- API Key: Ensure you have a valid Gemini API key and replace the placeholder in the script with your actual key.
The sendSummariesByEmail function retrieves the email addresses from column A and the corresponding summaries from column C of the Student sheet, then sends the summaries to the respective emails.
- To generate summaries, manually run the
generateSummariesfunction or set up a trigger to run it periodically. - To send summaries by email, run the
sendSummariesByEmailfunction manually or set up a trigger to run it periodically.
- Use
Logger.logstatements to debug and view logs in the Apps Script editor underView > Logs. - Ensure proper permissions are granted to the script for accessing the Google Sheet and sending emails.