【问题标题】:Gmail Apps script function to display Browser MsgBox from GMail AddonGmail 应用程序脚本功能,用于显示来自 GMail 插件的浏览器 MsgBox
【发布时间】:2020-02-20 04:58:31
【问题描述】:

我有以下工作代码,可根据特定条件验证收件人列表。但是,我希望用“Browser.msgbox”操作替换生成的“Logger.log”操作,出于某种原因,GMail App Addons 不允许我这样做:

function validateRecipients(e) {
  var toEmails = e.draftMetadata.toRecipients, ccEmails = e.draftMetadata.ccRecipients, bccEmails = e.draftMetadata.bccRecipients, domains = [], uniqueDomains = [];
  var allEmails = toEmails.concat(ccEmails, bccEmails);
  for (var i = 0; i < allEmails.length; i++) {
    domains[i] = allEmails[i].split("@").pop().split(".")[0]; 
  }  
  uniqueDomains = domains.filter(listUnique);
  if(uniqueDomains.length <= 2 && uniqueDomains.indexOf("verasafe") != -1) {
    Logger.log("This Message is Good to Go");
  }

  else if(uniqueDomains.length == 0) {
    Logger.log("This Message has no recipients");
  }

  else {
    Logger.log("Please Validate Receipients of this Message and Try again");
  }
}

【问题讨论】:

  • 这是不可能的。没有可供您使用的消息框对象,也没有办法返回已评估的 JavaScript 警报脚本。这必须是一个消息框吗?你能在侧边栏中使用类似消息的东西吗?
  • 任何提醒用户注意结果的东西,是的 - 除了 Logger.log
  • 这似乎真的不可能。有点意外。有时,“您确定”对话框可能非常重要 - 或者只是在弹出窗口中显示卡片的能力。耻辱:-(

标签: javascript google-apps-script gmail gmail-api gmail-addons


【解决方案1】:

部分回答

Browser.msg 不能用于 Gmail 插件,因为来自https://developers.google.com/apps-script/reference/base/browser

此类提供对特定于 Google 表格的对话框的访问。

【讨论】:

  • 是的,这是我的问题 :)
  • 那么我们应该使用什么对话框 API 来在 GMail 插件(Google 脚本)源中使用标准的确定/取消对话框提示用户?
【解决方案2】:

您不能在 Gmail 中使用 Browser.msg 或任何 UI 类。

但是,有一个 new feature called Card Service 用于为 Gmail 插件创建 UI。

希望这会有所帮助!

【讨论】:

    【解决方案3】:

    我目前能找到的最接近的是notification,它在卡片底部显示一条快速消息(在 Google 的 Material Design 中,它被称为 snackbar

    https://developers.google.com/apps-script/reference/card-service/notification

    除此之外,您需要更换一张新卡。

    function _navigateToCard(card: GoogleAppsScript.Card_Service.Card, replace: boolean)
    {
        var nav = CardService.newNavigation();
    
        replace ? nav.updateCard(card) : nav.pushCard(card)
    
        return CardService.newActionResponseBuilder()
          .setNavigation(nav)
          .build();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多