【发布时间】:2020-02-06 11:50:53
【问题描述】:
我正在构建一个 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,
"muteHttpExceptions": true
};
return UrlFetchApp.fetch('https://www.someAPI.com/api/endpoint', options);
}
如何将currentMessage 变量传递给callAPI 函数?根据文档,我们可以从动作函数中获得的唯一参数似乎是event,它只有表单字段数据。如果没有办法传递其他参数,有没有办法让那个函数直接在函数内部获取消息的上下文数据??
谢谢!
【问题讨论】:
-
您的问题解决了吗?
标签: google-apps-script gmail-addons