This script is designed to update Google Sheets with user information and generate mentor-specific questions based on the user's profile. It integrates with Google Apps Script and a generative AI API to provide recommendations and updates.
- Generate Mentor Questions: The script generates at least 3 personalized questions from each mentor based on the user's profile.
- Update Google Sheet: Automatically updates the sheet with the user's information and generated questions.
- Trigger Mechanisms:
- Form Submission Trigger: Processes user data when a form is submitted.
- Time-Based Trigger: Periodically checks for updates and sends emails to users as required.
The script includes predefined mentor data, such as:
- Name
- Bio
- LinkedIn profile
Defines the JSON structure for mentor questions to ensure consistency and proper formatting.
- Generates questions using the generative AI API.
- Inputs:
- User profile data
- Mentor information
- Output:
- Valid JSON containing questions for each mentor.
- Fetches the active Google Spreadsheet and data from the "Form Responses 1" sheet.
- Extracts relevant user data from the sheet to create a structured user profile object.
- Updates an existing row in the sheet with user data and generated questions.
- Main function triggered by form submissions.
- Updates the sheet with generated mentor questions.
- Periodically checks for updates and sends emails to users.
- Open Google Sheets and navigate to Extensions > Apps Script.
- Copy and paste the script into the Apps Script editor.
- Save the script with an appropriate name.
- Add the required triggers:
- Form Submission Trigger: Link
myFunction
to the form submission event. - Time-Based Trigger: Link
runsAfterAInterval
to run periodically (e.g., every hour).
- Form Submission Trigger: Link
- Replace the API key in the
fetchQuestionsAndCleanData
function:const mentorQuestions = await UrlFetchApp.fetch( "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=YOUR_API_KEY", { method: "POST", headers: { "Content-Type": "application/json" }, payload: JSON.stringify({ contents: [ { parts: [{ text: getSystemPrompt(userInfo) }], }, ], }), } );
- Replace
YOUR_API_KEY
with your actual API key.
Ensure the Google Sheet has the following columns:
- Email Address
- Are you a student (if applicable)
- Rate your technical knowledge
- Field of interest
- Description
- Additional columns for mentor questions and status flags.
- Fill out the Google Form linked to the sheet.
- The script will:
- Generate mentor-specific questions.
- Update the sheet with the new data.
- Optionally, send email notifications to users.
- Error Parsing JSON:
- Check the API response structure and ensure valid JSON.
- Sheet Updates Not Reflecting:
- Verify column indices and ensure the sheet structure matches the script.
- API Errors:
- Confirm API key validity and quota limits.