My GSM Gmail addon does not show the card

倖福魔咒の 提交于 2020-06-01 05:35:10

问题


I have built a GSM add on and published it for my domain. I built the code, on Google Apps Script and set it up in Google API Console. I installed it for my domain, but it does not show the card in Gmail It should show in the sidebar, and in the compose window. It works fine when I install the head version from within google apps script, but then I publish it to GSM for users in my organization it doesn't work. The purpose of the addon is to collect information from fields in a card and use that in an email template. I think it might be something to do with OAuth scopes but I am not sure. This is my very first GSM project and I don't know what OAuth scopes I should declare in my code and in the Google API console.

Here is my code, I have 2 files, appscript.json, and 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": ["openid, https://mail.google.com, https://www.googleapis.com/auth/gmail.addons.current.message.readonly, https://www.googleapis.com/auth/gmail.addons.execute"],
  "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"
      }
    }
  }
}

来源:https://stackoverflow.com/questions/61962709/my-gsm-gmail-addon-does-not-show-the-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!