我有一个Google表单接受回复并使用' Incoming Webhooks'向Slack发布每个新回复。跟踪支持请求票。我通过使用GitHub中的以下代码说明,最初没有遇到任何问题,一切都运行良好:
https://gist.github.com/akash1810/640a45d5997de1d95f4a
但是,我现在想要整合新的Google表单问题类型'文件上传'但我在链接中使用的脚本似乎没有处理推送通过Google表格上传到有效负载的文件。
通过Google表单上传的文件会显示在链接的Google表格(回复)中,作为Google云端硬盘中文件的直接网址。但是,当我在Logger中查看变量的内容时,它看起来像是实际文件(它在方括号内显示了Google Drive文件ID)。关于如何处理将此传递给Slack的任何建议?
以下是我使用的脚本(根据上面的链接):
/**
* ABOUT
* Google Apps Script to post a message to Slack when someone responds to a Google Form.
*
* Uses Slack incoming webhooks - https://api.slack.com/incoming-webhooks
* and FormsResponse - https://developers.google.com/apps-script/reference/forms/form-response
*
*
* AUTHOR
* Akash A <github.com/akash1810>
*
*
* USAGE
* Free to use.
*/
// Create an incoming webhook here - https://api.slack.com/incoming-webhooks
var POST_URL = "https://hooks.slack.com/services/XXXX/XXXX/XXXX";
function onSubmit(e) {
var response = e.response.getItemResponses();
var fields = [
{"title": "From", "value": e.response.getRespondentEmail()},
{"title": "When", "value": e.response.getTimestamp()}
];
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle();
var answer = response[i].getResponse();
fields.push({"title": question, "value": answer});
}
var summaryAttachment = {
"fallback": FormApp.getActiveForm().getTitle(),
"pretext": "<!channel> New response submitted to: " + FormApp.getActiveForm().getTitle(),
"title": FormApp.getActiveForm().getTitle() + " (responses)",
"title_link": "https://docs.google.com/spreadsheets/d/" + FormApp.getActiveForm().getDestinationId(),
"fields": fields,
"color": "#393939"
};
var responseAttachment = {
"fallback": FormApp.getActiveForm().getTitle(),
"title": "Respond via email? (mailto link)",
"title_link": "mailto:" + e.response.getRespondentEmail() + "?Subject=" + encodeURI(FormApp.getActiveForm().getTitle())
};
var options = {
"method" : "post",
"payload": JSON.stringify({
"username": "Feedback",
"icon_emoji": ":speech_balloon:",
"attachments": [summaryAttachment, responseAttachment]
})
};
UrlFetchApp.fetch(POST_URL, options);
}