小编uck*_*ckc的帖子

Gmail 插件将参数传递给由卡操作触发的函数

我正在构建一个 Gmail 插件,它可以创建一张只有一个表单按钮的卡片。单击后,我希望该按钮触发一个功能,将打开的电子邮件的内容发送到外部 API。

到目前为止,我有这样的事情:

function createCard(event) {
  var currentMessage = getCurrentMessage(event).getBody();
  var section = CardService.newCardSection();

  var submitForm = CardService.newAction()
    .setFunctionName('callAPI');

  var submitButton = CardService.newTextButton()
    .setText('Submit')
    .setOnClickAction(submitForm);

  section.addWidget(CardService.newButtonSet()
    .addButton(submitButton));

  var card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader()
    .setTitle('Click this button'))
    .addSection(section)
    .build();

  return [card];
}

function callAPI(event) {
  var payload = { "msg": msg }; // msg is the parameter I need to get from the function call
  var options = {
        "method"  : "POST",
        "contentType": "application/json",
        "payload" : JSON.stringify(payload),
        "followRedirects" : true, …
Run Code Online (Sandbox Code Playgroud)

google-apps-script gmail-addons

2
推荐指数
1
解决办法
1227
查看次数

标签 统计

gmail-addons ×1

google-apps-script ×1