我的 GSM Gmail 插件不显示卡片

My GSM Gmail addon does not show the card

我已经构建了一个 GSM 插件并为我的域发布了它。我在 Google Apps Script 上构建了代码,并在 Google API 控制台中进行了设置。我为我的域安装了它,但它没有在 Gmail 中显示卡片。它应该显示在侧边栏和撰写 window 中。当我从 google 应用程序脚本中安装 head 版本时,它工作正常,但随后我将它发布到 GSM 以供我组织中的用户使用,它不起作用。该插件的目的是从卡片中的字段收集信息并将其用于电子邮件模板。我认为这可能与 OAuth 范围有关,但我不确定。这是我的第一个 GSM 项目,我不知道我应该在我的代码和 Google API 控制台中声明什么 OAuth 范围。

这是我的代码,我有 2 个文件,appscript.json 和 code.gs。 code.gs:

function onGmailCompose(e) {
  console.log(e);
  var header = CardService.newCardHeader()
      .setTitle('Use Template')
      .setSubtitle('Use the template for sending an email after a review has been published.');
  // Create text input for entering the cat's message.
  var input2 = CardService.newTextInput()
  .setFieldName('FName')
  .setTitle('First Name')
  .setHint('What is the readers first name?');
  var input3 = CardService.newTextInput()
  .setFieldName('BookTitle')
  .setTitle('Reviewed Book Title')
  .setHint('What is the title of the book reviewed?');
  var input4 = CardService.newTextInput()
  .setFieldName('BookAuthor')
  .setTitle('Reviewed Book Author')
  .setHint('Who is the author of the book reviewed?');
  // Create a button that inserts the cat image when pressed.
  var action = CardService.newAction()
      .setFunctionName('useTemplate');
  var button = CardService.newTextButton()
      .setText('Use Template')
      .setOnClickAction(action)
      .setTextButtonStyle(CardService.TextButtonStyle.FILLED);
  var buttonSet = CardService.newButtonSet()
      .addButton(button);
  // Assemble the widgets and return the card.
  var section = CardService.newCardSection()
      .addWidget(input2)
      .addWidget(input3)
      .addWidget(input4)
      .addWidget(buttonSet);
  var card = CardService.newCardBuilder()
      .setHeader(header)
      .addSection(section);
  return card.build();
}
function useTemplate(e) {
  console.log(e);
  var FName = e.formInput.FName;
  var Title = e.formInput.BookTitle;
  var Author = e.formInput.BookAuthor;
  var now = new Date();
  var htmlIntro = '<p>Hello, ';
var html2 = ' Thank you for writing a book review at <a href="https://www.goodbookreviews.page">Good Book Reviews</a> on ';
var html3 = ' by ';
var html4 = '. You Review has been published to our site. Any personal information you included was NOT published, including first name, last name,  age, and email address. Only info you wrote about the book was published. You can see it right <a href="https://www.goodbookreviews.page./books-and-reviews/look-at-reviews"> here!</a> If you need anything else, feel free to contact us at support@goodbookreviews.page or reply to this email to contact us. <br> Happy Reading,<br> The Book Review Team</p>';
var message = htmlIntro + FName + html2 + Title + html3 + Author + html4;
  var response = CardService.newUpdateDraftActionResponseBuilder()
  .setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
                            .addUpdateContent(message, CardService.ContentType.MUTABLE_HTML)
                            .setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
  .build();
  return response;
}
function onGmailMessage(e) {
  console.log(e);
  var header = CardService.newCardHeader()
  .setTitle('Unavailable')
  .setSubtitle('Open the compose window to use template');
  var card = CardService.newCardBuilder()
  .setHeader(header);
  return card.build();
}

appscript.json:

{
  "timeZone": "America/Chicago",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
   "oauthScopes": ["https://www.googleapis.com/auth/gmail.compose"],
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Review Published Email Template",
      "logoUrl": "https://goodbookreviews.page/Logo.png",
      "useLocaleFromApp": true,
      "universalActions": [{
        "label": "Book Review ",
        "openLink": "https://www.goodbookreviews.page"
      }]
    },
    "gmail": {
      "contextualTriggers": [{
        "unconditional": {
        },
        "onTriggerFunction": "onGmailMessage"
      }],
      "composeTrigger": {
        "selectActions": [{
          "text": "Use Template",
          "runFunction": "onGmailCompose"
        }],
        "draftAccess": "NONE"
      }
    }
  }
}

我在 OAuth 同意屏幕页面中指定的范围在这里:

email

profile

openid

https://www.googleapis.com/auth/gmail.compose

Email, profile, openid默认添加,必填

以下是我在 GSM SDK 的配置页面中指定的范围。

https://www.googleapis.com/auth/userinfo.email

https://www.googleapis.com/auth/userinfo.profile

https://www.googleapis.com/auth/gmail.compose

您已经非常接近使该附加组件正常工作了。您只需要在清单文件中添加一些范围。您的最终清单应类似于此清单:

{
  "timeZone":"America/Chicago",
  "dependencies":{

  },
  "exceptionLogging":"STACKDRIVER",
  "oauthScopes":[
    "https://www.googleapis.com/auth/gmail.compose",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/script.locale"
  ],
  "runtimeVersion":"V8",
  "addOns":{
    "common":{
      "name":"Review Published Email Template",
      "logoUrl":"https://goodbookreviews.page/Logo.png",
      "useLocaleFromApp":true,
      "universalActions":[
        {
          "label":"Book Review ",
          "openLink":"https://www.goodbookreviews.page"
        }
      ]
    },
    "gmail":{
      "contextualTriggers":[
        {
          "unconditional":{

          },
          "onTriggerFunction":"onGmailMessage"
        }
      ],
      "composeTrigger":{
        "selectActions":[
          {
            "text":"Use Template",
            "runFunction":"onGmailCompose"
          }
        ],
        "draftAccess":"NONE"
      }
    }
  }
}

您的其余代码是正确的。我使用此清单部署了您的附加组件,并且有效。如果您需要进一步说明,请随时提出任何其他疑问。