AppsScriptPulse

Beyond the Limits: Automating Google Chat Space Archives in JSON and Docs for Gemini Analysis

As powerful as Google’s new AI tools are, those of us who live in Google Workspace have likely encountered some of their current limitations. One of the most significant for me is in Google Chat. While Gemini can analyse recent conversations, it seems to be limited to roughly the last 20 messages or 7 days of history. Crucially, it also can’t see or process messages sent by apps or webhooks, which are often the lifeblood of a technical team’s space.

This creates a knowledge gap. How can you analyse project history, debug an automated alert, or get a complete overview of a conversation if your tools only see a fraction of the data?

To solve this I’ve created an automated solution using Google Apps Script. This tool can archive an entire Google Chat space history into two powerful, synchronised formats:

  1. structured JSON file that serves as the definitive, machine-readable “source of truth”.
  2. clean, human-readable Google Doc, which is automatically generated from the JSON data.

This dual-output approach provides the best of both worlds: a portable data file perfect for backups or analysis, and a browsable document ideal for quick searches or for use as a direct data source in a Gemini Gem or other tools like NotebookLM.

Best of all, once configured, you can set up a time-driven trigger to run the script automatically, ensuring your archives are always kept up-to-date without any manual intervention.

Prerequisites

Before you begin, please ensure you have the following:

  • A Google Workspace Account: For setup this can only be a Google Workspace account, once it is configured it is possible to test with a personal consumer Gmail account.
  • Access to Google Cloud Platform (GCP): You will need the ability to create a new GCP project and enable APIs. The guide below will walk you through creating a fresh project, but if you are using a Google Workspace account, you may need to request a project depending on your organisation’s policies.
  • User-Based Access: This script runs as you, the user who authorises it. Therefore, it will only be able to see and archive Google Chat spaces that you are a member of.

The Setup Guide

Getting started is straightforward. The core logic is pre-packaged in a Google Sheet template. You just need to make a copy and connect it to your own Google Cloud project.

Step 1: Copy the Google Sheet Template

First, make your own personal copy of the Chat Archiver template.

➡️ Make a Copy of the Chat Archiver Template ⬅️

Step 2: Configure Your Google Cloud Project (GCP)

This is the most involved step, but it’s essential for giving your new sheet the permission it needs to access your Chat spaces.

  1. Create a Standard GCP Project:
    • Go to the Google Cloud Console.
    • Create a new project. Give it a memorable name (e.g., “My Chat Archiver”).
  2. Enable the Google Chat API:
    • In your new project, navigate to the “APIs & Services” > “Enabled APIs & services” and enable the Google Chat API and Google Drive API , or Enable the APIs
  3. Configure the Chat App (Crucial Step):
    • After enabling the API, you’ll be on the Google Chat API page. Click on the Configuration tab. Go to Chat API Configuration page
    • Fill in the required details to give your script an identity:
    • Under Interactive features, click the Enable interactive features toggle to the off position to disable interactive features for the Chat app.
    • Click Save.
  4. Configure the OAuth Consent Screen:
    • Google Auth platform > Branding. Go to Branding
    • If you see a message that says Google Auth platform not configured yet, click Get Started
    • Add an App name and support email
    • Choose a user type. Internal is best if you’re on a Workspace account. External will work for anyone but require you to add yourself as a test user (you can add up to 100 testers without the need of going through verification).
    • Click Next.
    • Under Contact Information, enter an Email address where you can be notified about any changes to your project, then click Next.
    • Under Finish, review the Google API Services User Data Policy and if you agree, select I agree to the Google API Services: User Data Policy, then click Continue.
    • Click Create.
  5. Link Your Copied Script to Your GCP Project:
    • In the Google Cloud console, go to Menu > IAM & Admin > Settings. Go to IAM & Admin Settings
    • In the Project number field, copy the value.
    • Open your copy of the Google Sheet.
    • Go to Extensions > Apps Script.
    • In the Apps Script editor, go to Project Settings (the cog icon ⚙️).
    • Under “Google Cloud Platform (GCP) Project”, paste the Project Number and click Set Project.

Your copy of the sheet is now correctly configured and authorised to make requests to the Chat API on your behalf.

Step 3: Run Your First Archive

  1. Refresh your copied Google Sheet. A new menu named Chat Archiver will appear.
  2. In the Config tab, paste a Google Chat space ID or full room URL and add your email address (you can share your copy of the Google Sheet with other users who will be able to jump to this step).
  3. Click Chat Archiver > Archive All Spaces.
  4. The first time, a dialogue will appear asking for authorisation. Grant the permissions to allow the script to run.
  5. The script will now run, creating both a JSON file and a Google Doc, and will place their links in the corresponding columns in the sheet.
  6. (Optional) Click Chat Archiver > Setup 15-Minute Trigger so setup a trigger to update the archive documents every 15 minutes.

Understanding the Outputs

The script produces two distinct files, each with a specific purpose:

  • The JSON File: The primary output is a structured JSON file. It takes the chat messages and uses a nested format, which groups replies under their parent message, makes it easier for data analysis with LLMs.
  • The Google Doc: Alongside the JSON, the script generates a clean Google Doc. This format is perfect as knowledge for a Gem or as a data source in NotebookLM. Crucially, this document is completely regenerated from the JSON data on every run. This means it is a “read-only” artefact; any manual changes will be overwritten.

Important Considerations and Limitations

While this solution is powerful and robust for many use cases, it’s important to understand its design limitations and potential areas for future improvement.

  • Access is User-Based (By Design) – The script runs with the permissions of the user who authorises it. This means it can only access and archive Google Chat spaces that the user is currently a member of.
    • Future Improvement: For a true, organisation-wide backup solution, this script could be adapted to use a Service Account. With domain-wide delegation granted by a Workspace administrator, a service account could access any chat space in the domain, regardless of membership. This is a more complex setup but is the standard for enterprise-level automation.
  • Archives are Text-Only – This solution is focused on archiving the textual content of conversations. It does not save file attachments like images, PDFs, or videos. The JSON data will note that a message contained an attachment, but it won’t contain the file itself.
  • Data is Append-Only – The script is designed to add new messages to the archive. It does not synchronise edits or deletions. If a message is edited in Google Chat after it has been archived, the JSON file will still contain the original text. If a message is deleted, it will remain in the archive.
  • Apps Script Execution Limits – Google Apps Script has built-in limits to prevent abuse.
    • Execution Time: A single script run is limited to 6 minutes for standard Gmail accounts or 30 minutes for Google Workspace accounts. For an exceptionally large space (many hundreds of thousands of messages), the very first archive could potentially time out. Using the “Archive Start Date” field is the best way to manage very large initial backfills.
    • File Size: There is a 50 MB limit on the size of a data blob that Apps Script can create. As the JSON archive grows, a single file may eventually hit this limit. For extremely large spaces, the script could be modified to create new files on a yearly or quarterly basis.
  • Not a Compliance Substitute for Google Vault – For organisations that require eDiscovery, legal holds, and retention policies for compliance reasons, Google Vault is the official, authoritative tool. This script should be seen as a powerful data extraction and analysis tool, not a substitute for an official compliance solution.

Ideas for Your Archive

Now that you have your complete chat history in a structured format, what can you do with it? Here are a few ideas to get you started:

  • Create a Project FAQ with Gemini: Provide the generated Google Doc or JSON file to Gemini and ask it to synthesise a “Frequently Asked Questions” document about a specific project. It can pull out key decisions, find links to important resources, and identify common questions your team has answered.
  • Generate an Infographic Summary: Use a prompt like, “Based on this JSON data, identify the top 5 most active members, the busiest day of the week, and the main topics discussed. Present this as data for an infographic.” You can use the Gemini App ‘canvas’ to create a webpage or feed the structured output into a design tool.
  • Onboard New Team Members: Give a new team member the Google Doc archive and ask Gemini to act as a project expert. They can ask questions like, “What was the final decision on the ‘Phoenix’ feature?” or “Summarise the key discussions from last March,” and get instant, context-aware answers.
  • Perform Topic and Sentiment Analysis: The structured JSON file is perfect for programmatic analysis. You could ask Gemini to write a simple script (or use a Colab notebook) to parse the messages, perform sentiment analysis over time to track team morale, or use natural language processing to identify recurring topics and pain points.
  • Build a Project Timeline: Ask Gemini to scan the archive for key dates, deadlines, and project milestones mentioned in the chat, then format the results as a timeline or a table that you can use for project retrospectives and reports.

Summary

Ultimately, this tool is about providing an easy way for you to unlock the value hidden in your team’s conversations. By moving beyond the current limitations and including every message, you create a better true source of truth for analysis and reporting. While we hope future updates to Gemini for Workspace will make this kind of deep integration seamless, for now, this solution gives you more control over your data and a process you can experiment with. I hope this guide helps you get started quickly and if you would like to explore enterprise level solutions get in touch.

Google Chat Apps: Publication experiences on the Google Workspace Marketplace

Image credit: Anton Shevchuk

It has finally happened! Bot Bender 2.0 is now available for installation from the Google Workspace Marketplace. In this post, I will walk you through the steps needed to get to the marketplace.

We’ve shared a couple of journeys to Google Workspace Marketplace publication but this is the first I’ve seen for publishing a Google Chat App. For people who have gone through the process it’s probably a familiar story of back and forth with the Marketplace review team.

In this post Anton Shevchuk shares how his Chat App received multiple rejects due to issues with the location of the support/privacy pages. The moral of the story is to be persistent, and don’t hesitate to push back if you believe the reviewers are mistaken. The post from Anton also outlines the other steps involved, including connecting the Google Workspace Marketplace SDK and configuring app visibility settings.

Source: Google Chat Bot. Publication on Google Workspace Marketplace

Google Workspace Developer Preview Program: New Card UI in Chat

You can apply to join the Google Workspace Developer Preview Program to get early access to certain features. Features in developer preview have already completed early development phases, so they’re ready for implementation. This program gives you the chance to shape the final stages of feature development with feedback, get pre-release support, and have your integration ready for public use on launch day.

The Google Workspace Developer Preview Program (DPP) gives you early access to new features. If you are developing Google Workspace products and solutions, it’s a great way to stay ahead of the curve and provide feedback before feature release. Anyone can apply to join the DPP, just follow the source link, but note that you can’t enroll with a gmail.com account.

New Google Chart Card UI has just been added for buttons, chips, collapsible sections, and overflow menus. These additions extend the capability of Google Chat, allowing the possibility for users to interact with external tools and services without leaving the chat and continually having to context switch.

The public documentation page includes a list of all active developer previews. While these pages don’t offer visuals of the features, existing DPP members received a nice set of visuals in the email update. This example includes chips and a customizable control button for a collapsible section:

I’d highly recommend registering for the DPP so you can see what is coming in Google Workspace.

Source: Developer Preview Program  |  Google Workspace  |  Google for Developers

New Advanced Google Workspace Events service for Google Apps Script


To subscribe to events using Apps Script, you can now use the Advanced Google Workspace Events service.

In the May 02, 2024 Google Apps Script release notes it was announced that a new Advanced Google Workspace Events service is available to let developers use the Google Workspace Events API directly in Google Apps Script. The Google Workspace Events API is a relatively new API, which was released to developer preview in January, 2024. The Google Workspace Events API uses a subscription model to handle resource changes. When you create a subscription, you specify the target resource (such as a Google Chat space or Google Meet meeting space) and the event types that you want to subscribe to. The API then sends notifications to your specified endpoint whenever an event occurs for that resource and event type.

In the case of the new Advanced Google Workspace Events service the linked documentation includes samples for using the new service with Google Chat. It’s worth noting that the Advanced Google Workspace Events service is designed specifically on managing subscriptions to events. While it lets you to control the flow of information and manage event subscriptions in your Apps Script projects, the actual processing and handling of event data occurs separately.

The linked documentation page provides sample code as well as outlines all the prerequisites.

Source: Advanced Google Workspace Events Service

Answer questions based on Google Chat conversations with a Gemini API powered Chat app

This tutorial shows how to make a Google Chat app that answers questions based on conversations in Chat spaces with generative AI powered by Vertex AI with Gemini. The Chat app uses the Google Workspace Events API plus Pub/Sub to recognize and answer questions posted in Chat spaces in real time, even when it isn’t mentioned.

Here is another great tutorial from the Google Chat DevRel team, this time showcasing how the Google Workspace Events API and some new Google Chat UI elements can be used to turn a Chat space into a Gemini Pro powered knowledge base.

The sample solution will let you consume your Chat space message history into a Firestore database. The Chat app is an intelligent agent that can then monitor for new questions and make suggestions using Gemini to generate content based on the previous messages.

There is quite a bit of setup required as part of this tutorial, but it provides a solid foundation for quickly scaling this to your needs.  A demonstration and explanation of the sample app was given as part of the Google Chat apps and APIs: Build connected workflows for the hybrid workplace session at Google Cloud Next and a recording might be available soon!

Source: Answer questions based on Chat conversations with a Gemini AI Chat app  |  Google Chat  |  Google for Developers

We’re bringing new generative AI and security innovations to businesses of all sizes to Google Workspace | Google Workspace Blog

we’re making it easy for organizations to extend the power of their data and custom AI models by using Vertex AI with Workspace as a platform, enabling next-generation workflows that are built right into Docs, Gmail, and other Workspace apps

Google Cloud Next ’24 has just started but already a number of exciting product updates have been announced, including the indications of a possible deeper integration of Vertex AI into Google Workspace.

In one of our recent Pulse updates we highlighted Dialogflow CX and Google Chat API integration is now in Developer Preview. The reason I feel this is an important development is Dialogflow CX lies at the heart of Vertex AI Agent Builder (formerly Vertex AI Search and Conversation … formerly Gen App Builder).

Vertex AI Agent Builder lets developers easily build and deploy enterprise-ready gen AI experiences via a range of tools for different developer needs and levels of expertise — from a no-code console for building AI agents using natural language

This integration is significant because it addresses a key challenge I’ve experienced as a Vertex AI Agent Builder trusted tester. Previously, using Google Workspace data in your agents required moving it to a Cloud Storage bucket. The new integration potentially streamlines this process, allowing seamless access to your Workspace data.

This aligns with a broader trend I’m seeing at Google Cloud Next: the emphasis on custom Generative AI-powered agents. Gabe Weiss’s demo in  this morning’s keynote showcased the potential of such agents to intelligently support users. Though details about the underlying technology were limited to Vertex AI Agent, the UI does hint at a gemini.google.com integration. You can see for yourself at the queued clip (this may change if Google trims the video).

#GoogleCloudNext

Source: We’re bringing new generative AI and security innovations to businesses of all sizes | Google Workspace | Google Workspace Blog

“going beyond basic bots” – Tutorial: managing projects with Google Chat, Vertex AI, and Firestore  

Image credit: CC-BY Google

This tutorial shows how to make a Google Chat app that a team can use to manage projects in real time. The Chat app uses Vertex AI to help teams write user stories (which represent features of a software system from the point of view of a user for the team to develop) and persists the stories in a Firestore database.

A recent episode of Totally Unscripted delved into “going beyond basic bots”, highlighting a couple of Google Chat app tutorials from the Google Developer documentation. One example, the “project management” Chat App, is worth mentioning in a Pulse post.

While this example uses Google Cloud Functions instead of Google Apps Script, as discussed in the episode, both approaches share many similarities. Deploying the project management app involves several steps, but I believe it’s a worthwhile investment to learn how to combine different solutions for building Google Workspace integrations. For developers seeking to expand their Google Workspace Add-on capabilities, this example serves as a valuable reference.

If you’re interested in using Firestore for data management but prefer Google Apps Script, Justin Poehnelt’s post on “Using Firestore in Apps Script.” is a great resource. This post provides a basic Firestore wrapper and links to other relevant Apps Script/Firestore libraries.

Source: Manage projects with Google Chat, Vertex AI, and Firestore  |  Google for Developers

Create a Google Chat Bot on your own data with Vertex AI Search and Google Apps Script

Create a Chatbot answering user questions based on your documents. RAG implementation with multiturn using Vertex AI Search and Apps Script

More GenAI, this time from Stéphane Giron looking at how Apps Script can be used to provide the glue for a Google Chat app powered by Vertex AI Search. In this example you can see how unstructured data like PDF documents can easily be uploaded to a Cloud Storage folder, which then become the knowledge base for the Chat app. The post includes a Google Apps Script snippet for sending messages to the Vertex AI Search API as well as instructions on how to create the chatbot, including how to import data into Vertex AI Search and how to integrate the chatbot into Google Chat.

The post is a great summary of what is possible when combining Google Chat and Vertex AI Search. If you are interested in finding out more about what is possible using Vertex AI Search with follow-ups Google provide a comprehensive guide.  

Source: Create a Google Chat Bot on your own data with Vertex AI Search and Google Apps Script

Tutorial: Respond to incidents with Google Chat, Vertex AI, and Apps Script

Imagen: photo looking over the shoulder of a robot looking at a screen with chat messages and hand writing notes

This tutorial shows how to make a Google Chat app that responds to incidents in real time. When responding to an incident, the app creates and populates a Chat space, facilitates incident resolution with messages, slash commands, and dialogs, and uses AI to summarize the incident response in a Google Docs document.

Paraphrasing noted Google Workspace Developer Expert, Romain Vialard, GenAI has made Google Chat apps a tangible prospect. This tutorial from the  Google Developers site is a great example of how you can use Google’s Vertex AI with Google Chat. The tutorial will help you create a Google Apps Script powered Chat app that is able to summaries the messages in a Google Chat space.

There is a lot to take away from this example, but here are some of the headlines:

  • Setting a Google Cloud Project to use the new Google Chat Advanced Service for Apps Script
  • Setup and code for making calls to Google’s Vertex AI PaLM API (LLM) from Google Apps Script
  • Using the responses from Vertex AI to generate new assets.

There is a lot more you can do from this starting point, but hopefully it gives you a great starting point.

Source: Respond to incidents with Google Chat, Vertex AI, and Apps Script  |  Google for Developers

Generally available: You can now call the Chat API from Apps Script with the Advanced Chat Service

The Advanced Chat service lets you use the Google Chat API in Apps Script. This API allows scripts to find, create, and modify Chat spaces, add or remove members to spaces, and read or post messages with text, cards, attachments, and reactions.

There have been a number of updates to the Google Chat API summarised in the linked release notes page. A recent announcement which might interest Google Apps Script developers is the generally available of a new  Advanced Chat Service. As noted in the official documentation:

The Advanced Chat service lets you use the Google Chat API in Apps Script. This API allows scripts to find, create, and modify Chat spaces, add or remove members to spaces, and read or post messages with text, cards, attachments, and reactions.

There are some perquisites to use the Advanced Chat service besides the usual turning it on before use, the main one being the requirement to use a standard Google Cloud console project rather than the default project created automatically.

Source: Google Chat developer platform release notes  |  Google for Developers