将 Slack 数据推送到 Google 个带有事件订阅的工作表
Pushing Slack data to Google Sheets w/ Event Subscription
我正在尝试在 Slack 上创建一个机器人,它将发送到私人频道(机器人所在的)的新消息数据发送到 Google Sheet。通过使用以下脚本,我成功地能够使用 Slack 斜杠命令后的数据执行此操作:
function doPost(e) {
if (typeof e !== 'undefined') {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
sheet.getRange(1,1).setValue(JSON.stringify(e));
}
}
我尝试使用与 Events API 相同的脚本,但它需要传递带有质询参数的请求,并且端点必须以质询值响应。使用 GScript 网络应用程序的 URL,我不断收到失败的响应。如何让 URL 验证握手与 Google Sheet 一起工作并使用正确的质询字符串进行响应?
HTTP Post 失败
这个修改怎么样?
The official document表示如下。这在你的问题中已经提到了。
challenge
: a randomly generated string produced by Slack. The point of this little game of cat and mouse is that you're going to respond to this request with a response body containing this value.
因此请修改您的脚本以从 doPost
返回 challenge
的值,如下所示。
修改后的脚本:
function doPost(e) {
if (typeof e !== 'undefined') {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
sheet.getRange(1,1).setValue(JSON.stringify(e));
}
var v = JSON.parse(e.postData.contents); // Added
return ContentService.createTextOutput(v.challenge); // Added
}
注:
- 当您修改Web Apps的脚本时,请将Web Apps重新部署为新版本。由此,最新的脚本被反映到Web Apps。请注意这一点。
参考文献:
已添加:
根据您对 I'm getting the same error.
的回复,我认为最新的脚本可能不会反映到 Web 应用程序。作为一个简单的脚本,请复制并粘贴以下脚本而不是您的脚本。并请将 Web 应用程序重新部署为新版本。那么,请再测试一下。
示例脚本:
function doPost(e) {
var v = JSON.parse(e.postData.contents);
return ContentService.createTextOutput(v.challenge);
}
我正在尝试在 Slack 上创建一个机器人,它将发送到私人频道(机器人所在的)的新消息数据发送到 Google Sheet。通过使用以下脚本,我成功地能够使用 Slack 斜杠命令后的数据执行此操作:
function doPost(e) {
if (typeof e !== 'undefined') {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
sheet.getRange(1,1).setValue(JSON.stringify(e));
}
}
我尝试使用与 Events API 相同的脚本,但它需要传递带有质询参数的请求,并且端点必须以质询值响应。使用 GScript 网络应用程序的 URL,我不断收到失败的响应。如何让 URL 验证握手与 Google Sheet 一起工作并使用正确的质询字符串进行响应?
HTTP Post 失败
这个修改怎么样?
The official document表示如下。这在你的问题中已经提到了。
challenge
: a randomly generated string produced by Slack. The point of this little game of cat and mouse is that you're going to respond to this request with a response body containing this value.
因此请修改您的脚本以从 doPost
返回 challenge
的值,如下所示。
修改后的脚本:
function doPost(e) {
if (typeof e !== 'undefined') {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
sheet.getRange(1,1).setValue(JSON.stringify(e));
}
var v = JSON.parse(e.postData.contents); // Added
return ContentService.createTextOutput(v.challenge); // Added
}
注:
- 当您修改Web Apps的脚本时,请将Web Apps重新部署为新版本。由此,最新的脚本被反映到Web Apps。请注意这一点。
参考文献:
已添加:
根据您对 I'm getting the same error.
的回复,我认为最新的脚本可能不会反映到 Web 应用程序。作为一个简单的脚本,请复制并粘贴以下脚本而不是您的脚本。并请将 Web 应用程序重新部署为新版本。那么,请再测试一下。
示例脚本:
function doPost(e) {
var v = JSON.parse(e.postData.contents);
return ContentService.createTextOutput(v.challenge);
}