【发布时间】:2020-09-19 07:14:22
【问题描述】:
所以我正在尝试创建一个 SlackBot,它可以跟踪对它发布的消息的反应。不过,我也在尝试从 Google 表格中读取数据,因此机器人的代码将位于连接到表单的 Google 脚本中。
我显然需要启用事件才能看到反应,第一步是接收和响应 Slack 发送的 POST 请求:
Our Request:
POST
"body": {
"type": "url_verification",
"token": "---",
"challenge": "---"
}
我必须做出如下回应:
HTTP 200 OK,
Content-type: text/plain,
"the challenge code"
当我收到 POST 请求时,它会覆盖 Google 表格的 1,1 方格,这不是很好,但更令人担忧的是,我的 doPost 函数没有运行。
这是我从 Slack 得到的反馈:
Your Response:
"code": 200
"error": "challenge_failed"
"body": {
<!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Error</title><style type="text/css">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">The script completed but did not return anything.</div></body></html>
}
现在,这是我的 Google 脚本中的所有代码。
function doPost(request){
var postJSON = request.postData.getDataAsString();
var sheet = SpreadsheetApp.getActiveSheet();
// doesn't happen
sheet.getRange(5, 3).setValue("YEAH");
// when I send a req using CURL, I get the message
// "The script completed but did not return anything"
return postJSON;
}
它已经部署为一个网络应用程序,而且我每次更改代码时都会更新它,所以这不是问题。
任何建议将不胜感激,谢谢!
【问题讨论】:
标签: javascript post google-apps-script slack-api