slack API 斜杠命令 - returns 502_service_error webhook 使用成功后
Slack API slash command - returns 502_service_error after the webhook is successfully used
我构建了一个我 运行 的斜杠命令,我的服务器使用 webhook 响应 URL 斜杠命令发出,消息发布到频道,但随后 Slack 显示一条私人消息说"Darn - that slash command didn't work (error message: 502_service_error)"
是什么让 Slack 认为我的命令失败了?我尝试添加即时响应,但仍然出现此错误。
该代码是一个 AWS Lambda 函数,Slash 命令正在调用一个 AWS API 网关来访问它。
这是我的 Python 代码,它使用 requests
到 return 数据 -
response = requests.post(
urllib.parse.unquote(response_hook), json={'attachments':[{'text': result, 'color': 'good'}], 'response_type': 'in_channel'},
headers={'Content-Type': 'application/json'}
)
经过更多的挖掘,最终找到了答案。我需要在我的函数末尾添加一个特定的响应,让 Slack 知道消息已成功接收。下面是我用来解决问题的 Python 代码 -
return { "isBase64Encoded": True, "statusCode": 200, "headers": { }, "body": "" }
您可能需要在 API 网关设置中启用 Lambda 代理集成才能正常工作,不过我默认启用了它。
已接受的答案是正确的,Slack 期望使用斜杠命令的“200”响应。在接收斜杠命令的 lambda 的处理函数中使用包含的 'callback' 参数也可以。
callback(null);
回调的第一个参数是一个错误,所以如果可以就传递 'null'。
AWS doc
Slack documentation
我构建了一个我 运行 的斜杠命令,我的服务器使用 webhook 响应 URL 斜杠命令发出,消息发布到频道,但随后 Slack 显示一条私人消息说"Darn - that slash command didn't work (error message: 502_service_error)"
是什么让 Slack 认为我的命令失败了?我尝试添加即时响应,但仍然出现此错误。
该代码是一个 AWS Lambda 函数,Slash 命令正在调用一个 AWS API 网关来访问它。
这是我的 Python 代码,它使用 requests
到 return 数据 -
response = requests.post(
urllib.parse.unquote(response_hook), json={'attachments':[{'text': result, 'color': 'good'}], 'response_type': 'in_channel'},
headers={'Content-Type': 'application/json'}
)
经过更多的挖掘,最终找到了答案。我需要在我的函数末尾添加一个特定的响应,让 Slack 知道消息已成功接收。下面是我用来解决问题的 Python 代码 -
return { "isBase64Encoded": True, "statusCode": 200, "headers": { }, "body": "" }
您可能需要在 API 网关设置中启用 Lambda 代理集成才能正常工作,不过我默认启用了它。
已接受的答案是正确的,Slack 期望使用斜杠命令的“200”响应。在接收斜杠命令的 lambda 的处理函数中使用包含的 'callback' 参数也可以。
callback(null);
回调的第一个参数是一个错误,所以如果可以就传递 'null'。 AWS doc Slack documentation