我正在使用松弛事件 API。我正在获取有关订阅事件的事件。 但是如何使用 python 请求发送响应。几秒钟后,slack 再次发回相同的事件 我需要将什么 json 发送回 slack 作为响应以停止获得相同的响应? 如果您知道代码,请提前致谢:)
@flask.route("/slack_webhook")
def slack_webhook():
print("Slack Webhook.....!!!")
data = json.loads(request.data.decode("utf-8"))
if 'challenge' in data:
return(data['challenge'])
if data['type'] == 'event_callback':
response = make_response("", 200)
response.headers['X-Slack-No-Retry'] = 1
print("returning response")
return response
else:
slack_event_handler.delay(data)
最佳答案
您需要做的就是在 3 秒内用 HTTP 200 OK
直接响应 Slack 的请求。如果您的应用在该时间内终止,这将自动发生。
如果您需要更多处理时间,您应该考虑将事件排队以供稍后处理或启动异步进程进行处理。
这是 documentation 中所说的内容:
Your app should respond to the event request with an HTTP 2xx within three seconds. If it does not, we'll consider the event delivery attempt failed. After a failure, we'll retry three times, backing off exponentially.
Maintain a response success rate of at least 5% of events per 60 minutes to prevent automatic disabling.
Respond to events with a HTTP 200 OK as soon as you can. Avoid actually processing and reacting to events within the same process. Implement a queue to handle inbound events after they are received.
关于python - 使用 python flask 的松弛事件 API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224205/