Constructing G Suite Add-ons along with your favourite tech stack


Posted by Jon Harmer, Product Supervisor and Steven Bazyl, Developer Advocate for G Suite

Let’s speak in regards to the fundamentals of G Suite Add-ons. G Suite Add-ons simplify how customers get issues completed in G Suite by bringing in performance from different functions the place you want them. They supply a persistent sidebar for fast entry, and they’re context-aware — that means they will react to what you’re doing in context. For instance, a CRM add-on can robotically floor particulars a few gross sales alternative in response to an e mail based mostly on the recipients and even the contents of the message itself.

Up till just lately, G Suite Add-ons leaned on Apps Script to construct Add-ons, however selection is all the time factor, and in some circumstances it’s possible you’ll wish to use one other scripting language.. So let’s discuss methods to construct Add-ons utilizing extra runtimes:

First, extra runtimes do not add any new capabilities to what you’ll be able to construct. What it does provide you with is extra selection and adaptability in the way you construct Add-ons. We’ve heard suggestions from builders that they’d additionally like the choice to make use of the instruments and ecosystems they’ve already realized and invested in. And whereas there have all the time been methods to bridge Apps Script and different backends that expose APIs over HTTP/S, it is not the cleanest of workarounds. .

So let’s take a look at a facet by facet comparability of what it seems wish to construct an Add-on with alternate runtimes:

operate homePage()

Right here’s the whats up world equal of an Add-on in Apps Script. Since Apps Script is extra akin to a serverless framework like GCF, the code is simple — a operate that takes an occasion and returns the UI to render.

// Hey world Node.js
const categorical = require(‘categorical’);
const app = categorical();

app.submit(‘/house’, (req, res) => {
let card =
sections: [
widgets: []

That is the equal in NodeJS utilizing categorical, a preferred internet server framework. It exhibits somewhat bit extra of the underlying mechanics — working with the HTTP request/response instantly, beginning the server, and so forth.

The largest distinction is the cardboard markup — as a substitute of utilizing CardService, which beneath the covers builds a protobuf, we’re utilizing the JSON illustration of the identical factor.

operate getCurrentMessage(occasion)
var accessToken = occasion.messageMetadata.accessToken;
var messageId = occasion.messageMetadata.messageId;
return GmailApp.getMessageById(messageId);

One other space the place issues differ is accessing Google APis. In Apps Script, the purchasers can be found within the world context — the APIs largely ‘simply work’. Shifting to Node requires somewhat extra effort, however not a lot.

Apps Script is tremendous straightforward right here. The truth is, usually we would not trouble with setting the token when utilizing extra permissive scopes because it’s completed for us by Apps Script. We’re doing it right here to make the most of the per-message scope that the add-on framework offers.

const google = require(‘googleapis’);
const OAuth2Client = require(‘google-auth-library’);
const gmail = model: ‘v1’ );

async operate fetchMessage(occasion)

The NodeJS model may be very related — somewhat additional code to import the libraries, however in any other case the identical — extract the message ID and token from the request, set the credentials, then name the API to get the message contents.

Your Add-on, Your approach

One of many largest wins for alternate runtimes is the testability that comes with utilizing your favourite IDE, language, and framework–all of which helps you make creating add-ons extra approachable.

Each Apps Script and alternate runtimes for G Suite Add-ons have essential locations in constructing Add-ons. In case you’re moving into constructing Add-ons or if you wish to prototype extra complicated ones, Apps Script is an effective selection.. In case you write and keep programs as your full time job, although, alternate runtimes assist you to use these instruments to construct your Add-on, letting you leverage work, code and processes that you simply’re already utilizing. With alternate runtimes for G Suite Add-ons, we wish to make it doable so that you can prolong G Suite in a approach that matches your wants utilizing no matter instruments you are most comfy with.

And do not simply take our phrase for it, hear from one in all our early entry companions. Shailesh Matariya, CTO at Gfacility has this to say about alternate runtimes: “We’re actually blissful to make use of alternate runtimes in G Suite Add-ons. The outcomes have been nice and it is a lot simpler to keep up the code. Traditionally, it might take Four-5 seconds to load information in our Add-on, whereas with alternate runtimes it is nearer to 1 second, and that point and effectivity actually provides up. To not point out efficiency, we’re seeing a few 50% efficiency improve and due to this our customers are capable of handle their workflows with just some clicks, with out having to leap to a different system and cope with the effort of fixed updates.”

Subsequent Steps

Learn the developer documentation for Alternate Runtimes and join the early entry program.