【问题标题】:Slack Slash commands error: failed with the error "operation_timeout"Slack Slash 命令错误:失败并出现错误“operation_timeout”
【发布时间】:2021-10-24 13:06:04
【问题描述】:

我正在使用 Slack Slash 命令向我的 AWS Lambda python 应用程序发送请求。

但是,发送命令后,Slack 正在返回消息failed with the error "operation_timeout"

虽然我收到了这条消息,但我的请求发送成功,工作完成。

我只是想知道如何摆脱slack发送的这条消息。

我知道 Slack 期望来自此链接 here 的 HTTP POST 200 OK 作为确认响应,但我确实在收到有效负载时发送了一个,如下所示:

lambda_handler.py

def slack_acknowledgment_response(resonse_url):

    # Make API Call to Slack API
    requests.post(
        resonse_url, 
        {'text': 'Test'}
    )


# This is my main event
def main(event, context):

    payload = parse_qs(event['postBody'])

    response_url = payload['response_url'][0]

    slack_acknowledgment_response(response_url)

    time.sleep(5)

我故意添加了 5 秒的睡眠时间,因为如果我的脚本运行时间超过 3 秒,即使我已经在 3 秒之前发送了确认,我也会收到此错误。

有人可以帮忙吗?

【问题讨论】:

  • 请分享复制所需的最少代码,我们需要查看代码。
  • 我已经用我调用它的地方更新了代码。你能帮忙吗
  • 谢谢! Lambda 函数的超时时间是多少?您是否已将其从默认的 3 秒更改?尝试增加到 10 秒,看看是否有效(只是扫一眼)
  • 我的 lambda 是 15 分钟。我在 3 秒内从 slack 获得了操作超时。所以我不明白怎么了
  • 您的代码仍然不完整-您能否添加slack_acknowledgment_response 的详细信息?阅读:stackoverflow.com/help/minimal-reproducible-example

标签: python aws-lambda slack slack-api


【解决方案1】:

正如您在链接中所说,slack 说the 200 response message must be received within 3000ms(3 秒)。但是,我认为您误解了期望。它想要的是对 Slack 发送给您的请求的 200 响应。您可以发送POST to the response_url within 30 seconds,但仍需要在 3 秒内进行初始响应。

如果您预计该过程需要 3 秒以上,您可能应该想办法进行异步处理。例如,将您在 Lambda 中收到的作业排队到 SQS 队列,然后使用通知的 response_url 发送响应(只要您可以在 30 秒内处理它)。

您可能想查看the answers to this question,了解如何让您的 Lambda 函数立即返回响应,然后通过第二个 Lambda 函数进行异步处理。

【讨论】:

    猜你喜欢
    • 2022-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多