我们有一个处理 Slack 斜杠命令的小型 Google Apps Script webapp。它直接从 Slack 执行一些方便的操作,例如向我们的工作表添加、更新和查询记录。大多数时候一切正常。但是,Slack API 需要在不到 3 秒的时间内收到请求的答复,否则它将超时。我们的 Google Apps 脚本并不总是能够在那个时间范围内做出响应,随着我们的工作表增长或我们的查询变得更加复杂,这种情况只会变得更糟。
Slack API 允许使用延迟响应的异步调用,但这意味着 Google Apps 脚本需要立即响应(在 3 秒内)并在后台执行一些工作。
我不知道如何在 Google Apps Script 中进行异步调用
我知道 Google Apps Script 不支持 Workers 并且我下面的解决方案因为ReferenceError: 'google' is not defined碰壁。(只需忽略 Payload 类,它会格式化 Slack 响应)
function doPost(request) {
var responseUrl = request.parameter.response_url
// This is how I try to circumvent the lack of threads in Google Apps Script
google.script.run
// Send an asynchronous slack response with result
.withSuccessHandler(function(payload) …Run Code Online (Sandbox Code Playgroud)