AppsScriptPulse

Google Workspace Developer News: Import data into Google Chat, more events supported for Events API, and more

Welcome to the third edition of the Google Workspace Developer News! Find out what’s new on the Google Workspace Platform.

Another great summary of Google Workspace Developer News put together by Chanel Greco from the Google Workspace DevRel team. The update includes information on:

Google Chat Enhancements

  • Import data from other messaging platforms, including historical memberships.
  • Send private messages in spaces with multiple people.
  • Add interactive buttons to messages.

Google Workspace Events API Updates

  • Subscriptions to Google Chat users now supported.
  • Lifecycle events sent when subscriptions expire.
  • Get() method added to Operations resource.

Google Workspace Add-ons

  • Link previews now supported in Google Sheets and Slides.
  • Third-party resource creation from the @ menu in Google Docs.

Other Updates

  • Drive file and folder storage limits increased to 500 million items per user.
  • Google Drive API v3 now provides information on installed apps.
  • Reports API event payload filtered to specified event name.
  • Chrome phasing out third-party cookies for enhanced privacy.

For a longer discussion and demos for link previews and third-party resources check out Totally Unscripted 5.3: Google Workspace Development: Now with a Side of Smart Chips!

Source: Import data into Google Chat, more events supported for Events API, and more

 

ReDriveApp: A new Google Apps Script library to replace DriveApp and restricted scopes 

Apps Script class that provides equivalent methods offered by the built-in DriveApp, but that does not require use of full ‘/drive’ OAuth scope (which is a “Restricted” scope”). Instead, uses only these Recommended (non-sensitive) and/or Sensitive scopes

When you use OAuth 2.0 to get permission from a Google Account to access their data, you use strings called scopes to specify the type of data you want to access on their behalf. For Google Workspace Add-on developers wanting to distribute your app in the Google Workspace Marketplace one consideration is only using the scopes required for your app. In the case of Google Drive a number of the scopes are classified by Google as “restricted”. To use “restricted” scopes there is an enhanced verification process, which requires Cloud Application Security Assessment (CASA) by an independent security assessor, which come at a cost and can be time consuming.

ReDriveApp is a new Apps Script community library published by Dave Abouav which makes it easier for developers to use reduced recommended scopes for integrating with Google Drive. As explained by Dave:

The built-in DriveApp service is an easy and powerful way to interact with Google Drive in your Google Apps Script projects, which is why so many developers make use of it. It’s one downside is that it forces your project to use the full ‘/drive’ OAuth scope, which is a “Restricted” scope.

In many cases though, projects don’t really need the full /drive scope for common tasks, and the Recommended /drive.file scope is sufficient. This allows your project to create new files, and open existing files if authorized by the end-user via the Drive Picker. Using it also avoids the aforementioned security review, and is less alarming to users when authorizing your app.

ReDriveApp is still work-in-progress and not an official Google project. There are a number of methods that still need to be implemented, but the project is open source and can be contributed to on GitHub. If you are planning or have already developed a Marketplace Add-on that has stalled due to enhanced verification for restricted scopes it could be worth looking at and contributing to this library.

Source: GitHub – ReDriveApp

Memoization in Apps Script with Cache Service

A generic Apps Script memoization function can be written to cache any function.

We’ve featured a couple of Apps Script optimisation techniques in the past. This example from Justin Poehnelt uses a technique found in many coding syntaxes of ‘memoization‘:

In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls to pure functions and returning the cached result when the same inputs occur again

For more background on when and why you might use ‘memorization’ you can read about Memorization [sic] in JavaScript. In the case of Google Apps Script developers have opportunities to integrate the built-in Cache Service and Properties Service to memorize function results in the context of the script, document or the user.

In the example provided in the source post by Justin it defaults to CacheService.getScriptCache() to store the memoized results but it would be easy to change this to CacheService.getUserCache() or CacheService.getDocumentCache(). With a little modification you could also include Properties Service.

To help you see how memoization works here’s a gist for both pure JavaScript and Apps Script techniques which you can copy and run in the Apps Script Editor. The results hopefully speak for themselves:

First run (cold start) and second run (warm start) with better performance for cached results first call

Source: Memoization in Apps Script | Justin Poehnelt

FetchApp: Open-source Google Apps Script library to enhance UrlFetchApp

Google Apps Script is often used to pull data from various services via HTTP requests. However, these requests sometimes fail due to network or service issues. The default behavior of UrlFetchApp is to throw an exception, which you have to catch. Otherwise, the script execution will be interrupted. We often need more: send the request again instead of failing. There is no built-in way to do retries in Apps Script. Solution – To solve this problem and not copy-and-paste code snippets from project to project, I created FetchApp – an open-source Google Apps Script library

This looks like a useful little library which puts a nice wrapper around the UrlFetchApp service. The wrapper includes options for: retries, delays (including exponential backoff), custom callbacks, code hints and automatic logging. The supporting post includes lots of documented code snippets for using the library which should make it easier to implement. A very handy drop in replacement if you are having to communicate with more sensitive API endpoints. The code is also on Github if you want to take a look at how the library is coded.

Source: FetchApp: UrlFetchApp with Retries

The complete guide to Smart Chips in Google Sheets

Image credit: Ben Collins

Learn how to use Smart Chips in Google Sheets to take full control of your data. Smart chips bring extra information to your Sheets.

Unleash the hidden power of Google Sheets with Smart Chips! Here’s a nice primer for our next episode of Totally Unscripted from Google Sheets magician, Ben Collins. You’ll have to tune in to the show to get the developer angle on Smart Chips, this post instead focusing on out-of-the-box features of Smart Chips in Google Sheets. Ben’s post is still incredible useful and in particular it was very interesting to read about data extraction from Smart Chips including the dot syntax when using Google Sheets formula/functions.

Follow the source link to find out more!

Source: The Complete Guide to Smart Chips in Google Sheets

Totally Unscripted: Google Workspace Development: Now with a Side of Smart Chips! 07 February 2024, 2024 at 1200 PT / 1500 ET / 2000 GMT

Totally Unscripted is back on 07 February 2024, 2024 at 1200 PT / 1500 ET / 2000 GMT. There have been a number of saucy updates and announcements around Smart Chips and other integrations to Google Docs, as well as Sheets and Slides.

In this episode we review how you can start to create Google Workspace Add-ons for Google Docs, Sheets, and Slides users which let you preview links from your third-party services. In addition we will be dipping into how you can let users of Google Docs add third-party resources from the @ menu.

For this episode we will be joined by some of the Google team behind Smart Chips with guests Allison Hodsdon (Technical Writer at Google) and Pierrick Voulet (Developer Relations Engineer (Google Workspace) at Google.

As always the show is broadcast live and you can ask questions via the YouTube chat, but also interested to hear in advance any of your burning questions for our panel using the comments section below.

Show Live/Recording link – https://www.youtube.com/watch?v=IPrWpV_bf4c

Changes to drive.google.com/uc URLs which break embedding images/files from Google Drive in your websites and AppSheet apps

Google Drive broke the ability to embed images with the /uc path. Here’s how to embed images from Google Drive in your website.

Previously Google Workspace developers could use a /uc path for embedding images and other files hosted in Google Drive. For example, images could be embedded in websites and emails using markup like:

<img src="https://drive.google.com/uc?export=view&id=1234567890abcdef" />

To my knowledge this was never an officially documented endpoint, but widely known about and shared within the community. Back in October 2023 Google announced Upcoming changes to third-party cookie requirements in Google Drive, which has started rolling out from the beginning of 2024.

The impact of this change is it breaks /uc embeds and these have started returning 403 errors. There is no reference to the /uc endpoint in the original announcement, which is why I think many people are only just finding out about the impact now. Google’s official guidance is to move to <iframe> with Google Drive publish and preview links. This post from Justin Poehnelt discusses the options and limitations for images.

There has also just been another announcement in the AppSheet community that Drive download URLs for embeddable content to be updated by May 1st, 2024. This is an extended window for AppSheet users and where possible Google will be emailing affected app owners where /uc urls have been detected. This announcement includes a link to a help page with tips for finding /uc occurrences in your AppSheet apps.

Source: Embed images from Google Drive in your website | Justin Poehnelt

How to automatically rename files in Google Drive with Apps Script and the Vertex AI Gemini API

Quickly rename files in Google Drive with Apps Script and Google Gemini AI. The script will automatically rename the files with a descriptive name based on the image content.

Amit Agarwal is celebrating 20 years of ‘Digital Inspiration’, one of my go to resources for Google Workspace tech tips, tutorials and how-to guides. This recent post from Amit is a great example of the types of solutions he regularly shares. This time Amit is looking at how the Generative AI capabilities of the Gemini API can be used to help rename images in Google Drive. To achieve this there Amit shares handy Apps Script snippets for finding images in a Google Drive folder, grabbing the thumbnail images as Base64 encoded strings before calling the Gemini Pro Vision API to get suggested filenames with the prompt:

Analyze the image content and propose a concise, descriptive filename in 5-15 words without providing any explanation or additional text. Use spaces instead of underscores.

For this solution an API key for Gemini Pro Vision is generated in Google AI Studio (formerly MakerSuite). There are still geographic restrictions on access to Google AI Studio, but given Apps Script runs on Google servers once you have a API key you can continue to use it without having to proxy a location.

Image credit: Amit Agarwal

Adding image capabilities to the GeminiApp Apps Script library has been on my TODO. Now I’ve got an example to play with it should be easier to do .. thank you Amit Agarwal.

Source: How to Automatically Rename Files in Google Drive with Apps Script and AI – Digital Inspiration

Unlock the power of your data with no-code! Join the CTS AppSheet Hackathon at the Google London 08 February 2024 

Be part of our AppSheet Hackathon Series in 2024! Join us at the Google office in London for this in-person event in February. Find out more.

My employer CTS/Appsbroker is hosting a free AppSheet Hackathon in Google Office in London on 08 February 2024. This in-person event is the first of four we are planning this year designed to bring both new and existing AppSheet users together to learn and share.

For new users there will be a guided ‘no-code along’ to help you get started, followed by a hackathon with on-hand support. You can find out more including registration by following the link (if you are able to attend my tip would be bring a work colleague as this will help you bottom out your business use cases). I’ll be attending the event so if you are able to attend please come and say ‘hi’.

Source: AppSheet Hackathon – CTS

Post and retrieve messages on Bluesky Social with Google Apps Script

Use Google Apps Script to automate actions on Bluesky Social using their API.

I’ve largely given up on X (formerly Twitter) and there are now numerous alternatives including Bluesky Social. If you would like to automate posting and getting messages from Bluesky Stéphane Giron provides a guide on how to communicate with Bluesky Social API using Google Apps Script. It includes detailed steps on how to obtain an app password, authenticate with Bluesky, retrieve messages for a user, and post a new message. The post also includes code snippets for each step, making it easy if you want to modify this integration to your own needs.

Source: Post and Get messages with Bluesky Social API and Google Apps Script