即使再次打开电子邮件,Gmail附件onTriggerFunction只能对每个电子邮件运行一次 [英] Gmail Add-Ons onTriggerFunction only ran once per email even if opening the email again

查看:61
本文介绍了即使再次打开电子邮件,Gmail附件onTriggerFunction只能对每个电子邮件运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建 Gmail加载项我们希望在调用插件的onTriggerFunction时根据某些业务逻辑来显示不同的卡.电子邮件打开后,该功能首次运行可以正常工作.

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.

我们有条件逻辑,但是Gmail似乎可以缓存首次通话返回第一张卡的结果.转至另一封电子邮件并返回原始邮件,不会再次调用onTriggerFunction,因此不会运行条件逻辑来更改呈现的初始卡.

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.

是否每次打开电子邮件时都可以运行onTriggerFunction,而不仅仅是第一次打开电子邮件时运行?

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:

插件中的操作或我们应用中的其他活动可能会影响重新打开以前显示的对话时应显示的内容.这意味着重新显示卡的旧副本会导致用户出现意外行为.

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.

推荐答案

不幸的是,目前没有办法(2019年7月)在每次打开电子邮件时强制触发器运行.您可以使用ActionResponseBuilder.setStateChanged(true)作为对按钮单击的响应,以指示Gmail清除缓存,但不能与普通卡响应一起发送.

Unfortunately there is no way at the moment (July 2019) to force the trigger to run every time the email is opened. You can use ActionResponseBuilder.setStateChanged(true) as a response to a button click to instruct Gmail to clear the cache, but it can't be sent along with a normal card response.

这篇关于即使再次打开电子邮件,Gmail附件onTriggerFunction只能对每个电子邮件运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆