10

I developed a Google Apps Script to process some emails automatically (connected to Gmail), more or less like a bot, and it's working as expected. It runs every minute, using a Time-driven trigger Minutes timer > Every minute:

enter image description here

Is it possible to distribute this "script" for other users (including commercially), or will it necessarily be open-sourced? (note: Google Apps Scripts are using Javascript internally)

I see Deploy as web app, Deploy as API executable, Register in Chrome Web Store, Deploy as web add-on, Deploy from manifest, but I don't know which one to use to offer this service for other users.

enter image description here

Also, will it necessarily be on the Chrome Web Store or are there other ways to commercially distribute/grant access to a customer to such apps?

TL;DR: How to distribute to customers a Google Apps Script that processes Gmail emails? (that needs to run automatically every minute).


Note: It seems that Gmail add-ons are available here: https://gsuite.google.com/marketplace/category/works-with-gmail. But it seems that we cannot sell an add-on commercially. Are Gmail add-ons necessarily free?

enter image description here

Note: the script is not linked to a precise browser or computer (thus it cannot be installed with a browser extension on a particular computer), it quietly runs on the Gmail server every minute.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • Have you looked at the documentation for [GMail Add-ons](https://developers.google.com/gmail/add-ons/) – Alan Wells May 19 '18 at 17:21
  • Yes @SandyGood but I see many deployment options in the menu shown here, so I don't know which one to choose to distribute to customers. Also I need the script to run every 2 minutes (it checks if new emails have come in a specific gmail label), is this possible with a commercial apps script / add on? – Basj May 19 '18 at 17:26
  • 1
    The only option is "Deploy from manifest" None of the other options are for a GMail Add-on. It's not a web app. It's not an API executable. Registering in the Chrome Web Store is for web apps as Chrome extensions, I believe. The "web add-on" option does not have an option for GMail, only Docs, Sheets, Forms and Slides. And it's definitely not an Android add-on, so the only thing left is "Deploy from manifest." Public GMail add-ons are being restricted. [You need to be approved](https://docs.google.com/forms/d/e/1FAIpQLSdQD9F5TXZvlpQcY1I6fvaZqLvULG1THhou3y5IpRRwjgwZYg/viewform) – Alan Wells May 19 '18 at 18:23
  • @SandyGood Thank you. Where can I distribute my Gmail add-on when it will be ready ? The only place I see is: https://gsuite.google.com/marketplace/category/works-with-gmail. But it seems that we cannot sell an add-on commercially. Are Gmail add-ons necessarily free? – Basj May 23 '18 at 22:16
  • 1
    You can implement a payment system in an add-on even though it's advertised as free. – Alan Wells May 23 '18 at 22:30
  • 3
    You certainly can't run a time based trigger in an add-on more than once per hour, though. If you want that level of querying, use the addon to configure a cron service on your server for people who are paying you, and from your server run your functions via the apps script API. (etc). – tehhowch May 24 '18 at 01:18
  • @tehhowch Which kind of manifest file / trigger is used to run an add-on once per hour? I have looked at the doc, but I don't find a trigger to put in the manifest file that allows to run every x hours. I've only found things like `"contextualTriggers": [{ "unconditional": { }, "onTriggerFunction": "buildAddOn" }]` – Basj May 28 '18 at 15:42
  • @Basj Gmail add-ons only have the unconditional trigger available - i.e. they can only activate when the user opens a new message and then selects the add-on. Other add-ons (i.e. Sheets & Docs) can use time-based triggers. Ref: https://developers.google.com/gmail/add-ons/guides/restrictions#wzxhzdk7wzxhzdk8use_apps_script_triggers – tehhowch May 28 '18 at 17:41

1 Answers1

2

Partial answer:

The page Restrictions about Gmail add-ons states that they don't provide a direct way to charge users to install an add-on:

We don't provide a way to charge users for installing add-ons, and add-ons can't include ads. However, you can roll your own payment system or call into an existing billing database. Your add-on can connect to non-Google services that bill users.

However, it's unclear for me if it's possible to run a time-driven background task (let's say once every 15 minutes) by a Gmail add-on. On the one hand, I see in the Restrictions page:

You can't create or use Apps Script simple or installable triggers in a Gmail add-on.

and time-driven triggers seem to be included in "simple" or "installable" category, but I'm not sure. For example, everyMinutes(n):

Specifies to run the trigger every n minutes. n must be 1, 5, 10, 15 or 30.

ScriptApp.newTrigger("myFunction")
    .timeBased()
    .everyMinutes(10)
    .create();

On the other hand, I see an example here with so-called Universal Actions:

/**
 * Run background tasks, none of which should alter the UI.
 * Also records the time of sync in the script properties.
 *
 * @param {Object} e an event object
 */
function runBackgroundSync(e) {
    ...
Basj
  • 41,386
  • 99
  • 383
  • 673
  • As per example, `runBackgroundSync` will be triggered only by the user. If the user explicitly clicks on the universal action. – V.i.K.i Mar 14 '19 at 07:01