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

1

7

I have a problem, probably stupid one, with slack slash command.

I config a /command that simple ask some data about covid infection that will be fetch at request, the answer work well but after some second (3000 ms for timeout) i have a message of error "failed with the error "operation_timeout".

Reading Slack documentation i must send a post message of confirmation and this i think is done by sending Post response with message, right? or i must send an answer before send the message?

This is the code:

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))
})

This is the result

And this is the Axios response.

{
  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]
}

I'm breaking my head from 8hour for this tricky issue. Thanks for your help :)


UPDATE

Dear community i resolve this issue with simple

res.send(slackBody)

deleting all axios config, now i have plain message, also if i send object Block the slack visualize Array and not the message...

Enface answered 24/3, 2020 at 13:49 Comment(1)
i am having the same issue but i am using python. Can you please help by stating what you sent in your payload?Bony
S
9

Glad you already fixed it! Meanwhile, Slack expects 200 status 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

Seeger answered 26/3, 2020 at 5:15 Comment(5)
Hi HenonoaH, thanks for reply. I tried to use response_url in payload with Axios but i received 2 message, one with response and on with timeOut error. Now with res.send seem work good also if sometimes i have some issue with the right format of message.Enface
Slack will attempt 3 times until you send a valid response in 3 seconds before it throws timeout error. github.com/slackapi/python-slack-sdk/issues/…Lillis
how can I send response later when I am using ack() to first acknowledge the request? I am not receiving neither response_url nor trigger_idOverburden
@DrashtiKheni Are you using Bolt? If that is the case you also have a response() method from Slash command callback similar to ack(). Refer: slack.dev/bolt-js/concepts#commandsSeeger
is it response or respond? if it is respond I already tried with it but it is giving me an error that respond is not a functionOverburden

© 2022 - 2024 — McMap. All rights reserved.