使用python flask的Slack事件API响应
作者:互联网
我正在使用slack事件API.我正在订阅活动上获取活动.
但是如何使用python请求发送响应.几秒钟后,slack再次发回相同的事件
什么json我需要发送回来作为回应停止获得相同的响应?
如果您知道代码,请提前多多谢谢:)
@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,slack-api 来源: https://codeday.me/bug/20190627/1303660.html