Slack API 斜线命令 - 成功使用 webhook 后返回 502_service_error

Maj*_*jor 2 slack-api

我构建了一个我运行的斜杠命令,我的服务器使用斜杠命令发出的 webhook URL 进行响应,消息发布到频道,但随后 Slack 显示一条私人消息,说“该死 - 该斜杠命令不起作用(错误消息: 502_service_error)"

是什么让 Slack 认为我的命令失败了?我尝试添加立即响应,但仍然发生此错误。

代码是一个 AWS Lambda 函数,Slash 命令调用 AWS API 网关来访问它。

这是我requests用于返回数据的Python 代码-

response = requests.post(
    urllib.parse.unquote(response_hook), json={'attachments':[{'text': result, 'color': 'good'}], 'response_type': 'in_channel'},
    headers={'Content-Type': 'application/json'}
)
Run Code Online (Sandbox Code Playgroud)

Maj*_*jor 6

经过更多的挖掘,最终找出了答案。我需要在我的函数末尾添加一个特定的响应,让 Slack 知道消息已成功接收。下面是我用来解决问题的 Python 代码 -

return { "isBase64Encoded": True, "statusCode": 200, "headers": { }, "body": "" }
Run Code Online (Sandbox Code Playgroud)

您可能必须在 API 网关设置中启用 Lambda 代理集成才能使其正常工作,但默认情况下我已启用该功能。