Gmail Add-Ons onTriggerFunction only ran once per

2019-03-19 09:12发布

We're building a Gmail Add-On however we wish to show a different card on depending on some business logic when the add-on's onTriggerFunction is called. This works fine for the first time the function runs when an email opens.

We have the conditional logic, but Gmail appears to cache the result of the initial call returning the first card. Going to another email and back to original, the onTriggerFunction is not called again, so the conditional logic is not run to change the initial card rendered.

Is there anyway to get the onTriggerFunction to run every time an email is opened, not just once the first time the email is opened?


Here's an example add-on with a trigger function that returns a single card displaying the current time:

Code.js

function buildAddOn(e) {
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle(new Date().toLocaleTimeString()));  

  return [card.build()];
}

appsscript.json

{
  "timeZone": "GMT",
  "dependencies": {
  },
  "oauthScopes": ["https://www.googleapis.com/auth/gmail.addons.execute"],
  "gmail": {
    "name": "Minimal example",
    "logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
    "contextualTriggers": [{
      "unconditional": {
      },
      "onTriggerFunction": "buildAddOn"
    }],
    "primaryColor": "#4285F4",
    "secondaryColor": "#4285F4",
    "openLinkUrlPrefixes": ["https://mail.google.com/"],
    "version": "TRUSTED_TESTER_V2"
  }
}

When navigating to older conversations a spinner is displayed followed by the current time. However, when navigating back to previously displayed conversations the old value of the time is displayed instantly, suggesting some caching is taking place:

demo of the issue

Actions inside the add-on, or other activity in our app can affect what should be displayed when re-opening a previously displayed conversation. This means that redisplaying an old copy of the card results in unexpected behaviour for the user.

0条回答
登录 后发表回答