Today I had the task of implementing a newsletter for internal updates and decided to use Google Apps Script since I was already using it for managing the project data. Based upon past experiences with emails using HTML I need this area was full of landmines and I didn’t want to navigate through it. 💣
So I decided to use MJML with Google Apps Script.
Sending emails using Google Apps Script is a common task, however, creating HTML emails that render consistently across different email clients and that look visually appealing can be challenging.
Justin Poehnelt’s post on DEV Community, “Using MJML in Google Apps Script to Send Beautiful Emails,” offers a solution to this problem. MJML is a markup language that makes it easy to create responsive HTML emails. It removes some of the complexities of HTML email development, allowing users to focus on the content of their emails.
In the post, Justin explains how to use MJML with Google Apps Script to send beautiful, responsive emails. He also mentions that he has published a library, MJMLApp, that “hides the gnarly bits” of using MJML with Google Apps Script. This library is available on GitHub in the mjml-apps-script repo where you can find the library ID and basic usage information.
As a Google Workspace Developer Advocate, I’m always exploring innovative ways to leverage technology. I’m thrilled to share my new Jupyter Notebook that showcases the power of Gemini and the Google Calendar API for productivity coaching. 🚀✨
This notebook dives into:
– Using Gemini’s multimodal capabilities to analyze calendar data. 📅
– Leveraging function calling to connect Gemini with Google Workspace APIs. 🔗
– Developing a personalized AI productivity coach. 🧑🏫
It’s amazing to see how generative AI can transform the way we work and optimize our time. ⏳
Explore the notebook on GitHub and discover how to build your own AI-powered productivity tools! 🛠️
Are you struggling to manage your time effectively? Mohammad Al-Ansari, Google Developer Advocate, has recently shared how the Gemini API can act as a personal productivity coach. The solution uses a Google Colab notebook, which is connected to the Google Calendar API. The Gemini API is used to provide personalized insights and recommendations to boost your productivity and improve your work/life balance. For those who don’t know, Google Colab is a free cloud-based platform for running Jupyter Notebooks, which are interactive coding environments that allow users to write and execute code and can be a useful tool to have in the toolbox when exploring data.
Some of the key features in Mohammad’s ‘Productivity Coach’ are:
Function Calling: This notebook uses Gemini’s ‘function calling’ capabilities, allowing it to dynamically interact with the Google Calendar API and retrieve real-time data. This ensures that the analysis and recommendations are always up-to-date and relevant to your current schedule.
Google Workspace Integration: By integrating with the Google Calendar API, this notebook shows how the Gemini API can be seamlessly integrated with other Google Workspace services. This opens up exciting possibilities for quickly experimenting with other Workspace data sources, such as Google Docs, Sheets or Drive.
Personalized Coaching: As a bonus you can see how Gemini can act as your personal productivity coach, so if nothing else you can get some tailored guidance and support about your own calendar
Imagine that you write in plain English what you want to do in Google Workspace (eg. workflows) and it happens just like magic. Insert text prompt, Gemini will generate the code for you and run it immediately. A dream? No, reality, thanks to my conceptual and practical idea of how to implement AI Agents in Google Apps Scripts to leverage the V8 runtime.
Ivan Kutil has explored the concept of AI Agents in Google Apps Script, enabling Google Workspace automation via plain English descriptions. Users describe their automation needs in natural language, which is then processed by Gemini API to generate the necessary code. The generated code is then executed in your Google Apps Script project.
Ivan’s solution uses the gemini-2.0-flash-thinking-exp-01-21 model, an experimental model within Vertex AI specifically designed to reveal its ‘thinking process’, resulting in more reliable code generation. The enhanced reasoning capabilities of this model are particularly beneficial for complex automation tasks, making it a powerful tool for Google Workspace customisation.
To ensure that the agent is doing the right thing, the clever bit is you can test the execution via a dry-run, where the code created with Gemini Flash Thinking is sent to an internal ‘Tester’ agent, which uses Gemini to comment on the code and summarises it in a log. It’s important to review the script before running it, as Ivan accepts no responsibility for the results of the script. Another nice feature is the generated code is stored in the Cache, so after running a dry-run and then a run, the same version will be executed within the Cache limit (currently set to 5 minutes).
This solution, which mirrors Gemini for Workspace’s ability to generate and execute basic Python code, suggests a future where Gemini for Workspace could write and execute Apps Script code for basic tasks. This has the potential to transform how users interact with and automate their Google Workspace environments.
If you are interested in a version of Ivan’s solution that incorporates my GeminiApp library, follow this link. For additional information on Ivan’s solution including setup instructions follow the source link.
If you have domain-specific knowledge that you want an LLM to leverage, you probably have a use case for fine-tuning. Fine-tuning can significantly improve how well the model understands and responds to your queries, whether it’s legal documents, medical texts, financial reports, or niche industry data.
The most crucial step in this process is structuring your data correctly. If your dataset is well-organized and formatted properly, the rest of the workflow becomes much more manageable. From there, it’s just a matter of setting up a few configurations and automating parts of the process with Apps Script. That’s where things get interesting and surprisingly efficient.
Archive Google Sheet Data with Google Sheets API Advanced Service in Google Apps Script
Keeping your Google Sheets organised can be a chore. A recent tutorial by Scott Donald shows you how to automatically archive old rows based on multi-column parameters using Google Apps Script and the Advanced Sheets API, making data management easier and more efficient. This post highlights Scott’s approach to scripting a solution, including how to set up the Sheets API, the main components of the script, and potential applications.
As always Scott packs in a lot of useful tips and guidance; in particular, the tutorial highlights how to archive data using just five API calls, potentially making it faster than the standard SpreadsheetApp approach. Scott also details how to modify the script to suit different processes and includes details on his SsReq class. It provides a structured way to perform common operations like retrieving data, finding rows based on criteria, copying rows, appending rows, and removing rows, making it a great addition to your personal Apps Script toolbox.
For detailed explanations, code examples, and helpful tips, consult the complete tutorial.
Tired of manually processing invoices? I recently built a demo that automates this tedious task using the power of Gemini, AppSheet’s new Gmail integration, and a custom Apps Script library. Let me show you how it works!
Here’s the setup:
Gmail Integration: AppSheet’s new Gmail integration allows you to trigger automations based on incoming emails. I’ve set it up to monitor a specific Gmail label called “Invoices”.
Apps Script Library: Using my “GeminiApp” (available on Github) which simplifies the interaction with Google’s Gemini AI models directly from Apps Script. This library handles the heavy lifting of making API calls and managing responses.
Controlled Generation: Gemini’s “Controlled Generation” feature lets me define a JSON schema that structures the AI’s output. This is key for extracting invoice data in a consistent, machine-readable format.
The Workflow:
Invoice Received: When an invoice email arrives and is labelled “Invoices”, AppSheet’s Gmail integration kicks in.
Automation Triggered: AppSheet triggers an automation that calls a custom Apps Script function called jsonControlledGeneration.
Data Extraction: The jsonControlledGeneration function uses the GeminiApp library to send the email body to Gemini with a predefined JSON schema for invoice data.
Structured Output: Gemini processes the email content and extracts the relevant invoice details (e.g., invoice number, supplier name, date, amount) in a JSON format that adheres to the schema.
Downstream Processing: The structured JSON output can then be easily returned to the AppSheet automation for further actions, such as automatically populating your data table, updating a database, or triggering a payment process.
If you would like to try this yourself, instructions are provided below.
Want to try it yourself?
To set this demo up you will either need a Google AI Studio API key or a Google Cloud project with Vertex AI enabled. Information on both these setups is included in the GeminiApp Setup Instructions. Once you have these you can follow these steps:
Open the Invoice Tracker template and click ‘Copy and Customize’, then click OK on the Error Creating App: Apps Script function is invalid error
Navigate to appsheet.com and from your ‘recent’ apps open the ‘Invoice Tracker’ app
Open Automations and for the ‘New Invoices’ event under the Gmail Event Source, click Authorize, then
In the ‘Add a new data source’ enter a name e.g. Invoices Trigger, click the Gmail button and follow the authentication steps
Once complete in the AppSheet Automation settings select your Gmail account and a Label to watch
In the Process section click on the GeminiApp task and click on the blue file icon, then select your copied version of the Apps Script project and click Authorize
Once Authorize, from the Function Name select jsonControlledGeneration
Step 7: Click on the blue file icon, then select your copied version of the Apps Script project
The Power of Controlled Generation
Controlled Generation is a powerful way for extracting information from unstructured data like emails. By defining a JSON schema, I can specify exactly what information I want Gemini to extract and how it should be structured. This ensures that the output is consistent and reliable, eliminating the need for manual cleanup or post-processing.
Here’s an example of a simple JSON schema for invoice data:
const schema = {
"type": "object",
"properties": {
"Invoice Reference": {
"type": "string",
"description": "Unique identifier for the invoice"
},
"Supplier Name": {
"type": "string",
"description": "Name of the supplier"
},
"Invoice Date": {
"type": "string",
"description": "Date the invoice was issued",
"format": "date"
},
"Due Date": {
"type": "string",
"description": "Date the invoice is due",
"format": "date"
},
"Invoice Amount": {
"type": "number",
"description": "Total amount due on the invoice"
},
"Notes": {
"type": "string",
"description": "Additional notes related to the invoice",
"nullable": true
}
},
"required": ["Invoice Reference"]
}
Creating JSON Schemas with Gemini
Creating JSON schemas can seem a bit daunting at first, but Gemini can actually help you with that too! If you have sample data in a Google Sheet, you can use the Gemini Side Panel to generate a schema automatically. Just highlight the data and ask Gemini to create a JSON schema for you. You can even provide a description for each property to make your schema more understandable. Below is a prompt you can use in the Gemini Sheet Side Panel to generate a schema for your own data:
I'm using Controlled Generation with the Gemini API as described in the document https://drive.google.com/file/d/1ETKHlEUDQzJ-f2fmAzsuDjcwdt1D7R2y/view?usp=drive_link
I need help creating a JSON schema to capture data from a screen.
Could you generate a JSON schema suitable for using Controlled Generation with the Gemini API? I want to extract specific information from what's displayed on my screen.
Here are my requirements:
* **Comprehensive Schema:** The schema should be designed to capture a variety of relevant data points from the screen.
* **Detailed Descriptions:** Please include a clear and concise \`description\` for each \`property\` in the schema. This will help me understand the purpose of each field.
* **Format Specification:** If any columns contain date or datetime data, please use the \`format\` field to specify the appropriate format (e.g., "date", "date-time"). This is crucial for accurate data parsing.
* **Output Example:** Please provide the schema in the following format:
```
const schema = {
description: "Description of the data",
type: "array", // or "object", depending on the structure
items: { // If type is array
type: "object",
properties: {
propertyName: {
type: "string", // or other appropriate type
description: "Description of the property",
format: "date", // or "date-time", if applicable
nullable: false, // or true
},
// ... more properties
},
required: ["propertyName"], // If any properties are required
},
properties: { // If type is object
propertyName: {
type: "string", // or other appropriate type
description: "Description of the property",
format: "date", // or "date-time", if applicable
nullable: false, // or true
},
// ... more properties
},
required: ["propertyName"], // If any properties are required
};
```
Limitations and future developments
While the beta Gmail integration in AppSheet marks a significant new feature, it’s important to note a current limitation is support for processing email attachments. Currently, the integration focuses on metadata such as sender name, subject, and message body, but the AppSheet team have acknowledged attachment support will be added in the near future.
Looking ahead, at Google Cloud Next 2024 the AppSheet team announced an upcoming “Gemini Extract” feature, currently in private preview. This feature intends to include a native Gemini ‘controlled generation’ feature which would let app creators select the data fields they would like populated from sources including images and text. This should be a more intuitive approach to data extraction, directly integrating Gemini capabilities into AppSheet. The Next video includes a Google URL to sign up to the Gemini Extract feature https://goo.gle/appsheet-previews?r=qr
Summary
The Invoice Tracker example hopefully highlights the opportunity for streamlined solutions with data extraction with AppSheet’s Gmail integration, Gemini, and Apps Script.The GeminiApp library also simplifies the integration of Google’s Gemini AI models into Google Workspace, providing developers with tools to create sophisticated AI-powered applications.
Using the structured JSON output with Controlled Generation can help AppSheet creators by making it easier to ensure you get the data back in a suitable format including the type of data you need, such as dates. With the GeminiApp library, rapid prototyping is achievable, in the ‘Invoice Tracker’ example I was able to get a functional prototype up and running in under 30 minutes.
AppSheet’s Gmail integration, generally available to all AppSheet and Google Workspace Core users, can trigger automations directly from incoming emails without requiring app deployment. Combined with Apps Script functions this opens the door to some powerful opportunities for AppSheet creators. Integrating Gemini-powered AI extraction with AppSheet and Apps Script provides an innovative solution for automating data extraction from emails. By taking advantage of these capabilities, citizen developers can create efficient and user-friendly solutions.
We’re pleased to announce the public preview of Gmail integration with AppSheet – something we know has been a longstanding community request. With this preview launch, your Gmail inbox can seamlessly connect to the full breadth of downstream processes AppSheet automation already offers.
AppSheet has introduced a Gmail integration in public preview, offering a workaround for situations including third-party applications that lack direct integration with Google Workspace via add-ons or APIs. With this new feature users can now connect their Gmail inboxes to AppSheet, enabling incoming emails to trigger various automations.
How it Works
Users can link their AppSheet apps to authorized Gmail accounts and select specific labels in their Gmail inboxes for monitoring. When an email arrives with a designated label, AppSheet receives information about the email, including the sender, subject, and body. This information can then be used to automate various tasks and processes within the AppSheet platform.
Things to Note
Currently, the beta release does not include support for attachments, but AppSheet is working on adding this feature for the full release later this year. Also, Gmail cannot be used as a full data source in AppSheet. To save Gmail messages in an app table, users need to create a process to add the email data.
Availability and Feedback
The Gmail integration is rolling out to all AppSheet users soon as part of the preview and the AppSheet team is encouraging users to provide feedback on this new integration. To read more and provide feedback follow the source link
Discover how to combine Imagen 3 and Google Sheets for rapid image creation. Automate your workflow and generate visuals in bulk.
Have you ever wished you could create a bunch of images without the hassle of typing in each prompt one by one? Well, Stéphane Giron has shared a clever solution using Google’s Imagen 3, Google Sheets, and Apps Script to streamline this process. While Gemini for Workspace is rolling out to more users and includes Imagen 3 for image creation in apps like Slides and the Gemini side panel, it doesn’t offer an easy way to create images in bulk. That’s where this method comes in. Instead of making images one at a time, this approach allows you to generate multiple images at once, saving you time and effort.
To get started with this method, you’ll need a Google Cloud Project and creating a service account (see the Build an AI slides reviewer with Gemini tutorial for instructions on setting this up). Once that’s set up, you create a Google Sheet with a column for your text prompts, and another for the links to the generated images. The images are automatically saved into a specific folder in your Google Drive.
The real magic happens with Apps Script. It uses Vertex AI to connect with the Imagen 3 model. The script reads each prompt from your sheet, sends it to Imagen 3 to create an image, and then stores the image in Google Drive. It also helpfully adds the image’s link back into the Google Sheet.
Check out the source post for the required code and instructions.
Learn how to automatically maintain consistent formatting, styles, and date formats when new Google Form responses are added to your Google Sheets.
Tired of Google Form responses messing up your carefully formatted Google Sheets? When new submissions come in, they often ignore the styles you’ve set, resulting in inconsistent looking data. Amit Agarwal, has created a guide that uses Google Apps Script to automatically maintain consistent formatting when new responses are added.
Google Forms does not apply any formatting when it adds new response data to a Google Sheet; this means that custom fonts, alignments, and date formats can be lost. Amit’s solution uses Google Apps Script to copy the formatting from the previous row to the new row, ensuring all data has a consistent look. The Apps Script runs automatically when a new form is submitted and identifies the new row and copies the formatting from the row above.
The guide provides a complete script with instructions for adding it to your Google Sheet and setting up a trigger. The script uses the copyFormatToRange method, which is designed specifically for copying only formatting between ranges. If you want to make sure your Google Sheet stays neatly formatted, check out Amit’s full guide to learn how to set up this handy automation for yourself.
Google Apps Script to check that a date submitted via a Google Form is both in the future and falls on a Wednesday.
Google Form question asking for a date to be entered
The following Google Apps Script is designed to check that a date submitted via a Google Form is both in the future and falls on a Wednesday. This was developed as part of a newsletter submission process to help validate information and inform a user when they had not followed the instructions. It has been developed for UK dates and may need adjusting for your own time zone.
I use Google Apps Script to support staff and students in my job. I enjoy dabbling with creating tools to help with automation and I freely share my learning experiences on my blog, where I also have a number of useful Google Add-ons: www.pbainbridge.co.uk