松弛斜线命令工作但发送 "failed with the error "operation_timeout""

slack slash command work but send "failed with the error "operation_timeout""

我有一个问题,可能是一个愚蠢的问题,使用 slack slash 命令。

我配置了一个简单的 /command 询问一些关于 covid 感染的数据,这些数据将根据请求获取,答案很好,但在几秒钟后(超时 3000 毫秒)我收到一条错误消息 "failed with the error " operation_timeout”。

阅读 Slack 文档我必须发送 post 确认消息,我认为这是通过发送 Post 响应消息来完成的,对吧?或者我必须在发送消息之前先回复?

这是代码:

app.post('/covid', async (req, res) => {
console.log(req.body)
const respUrl = req.body.response_url
slackBody = {
    "text": "Test"
}

await axios.post(respUrl, JSON.stringify(slackBody), {
    headers: {
        'Content-Type': 'application/json',
    }
})
            .then(function (response) {
                console.log(response.data);
                console.log(response.status);
                console.log(response.statusText);
                console.log(response.headers);
                console.log(response.config);
            })
            .catch((e) => console.log(e))
})

这是 Axios 响应。

{
  url: 'https://hooks.slack.com/commands/TU7AFJ1RU/1022360678069/tTuQ4NJhgmnb58FNPeubZUR5',
  method: 'post',
  data: '{"text":"Test"}',
  headers: {
  Accept: 'application/json, text/plain, */*',
  'Content-Type': 'application/json',
  'User-Agent': 'axios/0.19.2',
 'Content-Length': 15
},
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus]
}

为了这个棘手的问题,我从 8hour 开始就崩溃了。感谢您的帮助:)


更新

亲爱的社区,我用简单的方式解决了这个问题

res.send(slackBody)

正在删除所有 axios 配置,现在我有简单的消息,如果我发送对象 Block the slack visualize Array 而不是消息...

很高兴您已经修复了它!同时,Slack 期望 200 个状态 within 3 seconds if it doesn't get any response then it will throw "operation timeout" error. You can also send an acknowledgment to the slack channel with response_url you got from the Slash command payload. For more, https://api.slack.com/interactivity/handling#message_responses