Python Telegram bot‘ s Webhook进入无限循环
我构建了一个简单的电报机器人,该机器人在Google Cloud功能上运行。我的Webhook看起来像这样:
def webhook(request):
bot = telegram.Bot(token=os.environ["TELEGRAM_TOKEN"])
if request.method == "POST":
update = telegram.Update.de_json(request.get_json(force=True), bot)
#my code calls functions in here
return "ok"
此时的问题是我的代码运行时间太长,这会导致电报或Google Cloud(还没有完全弄清楚这一点)来重新发送请求,创建更多实例,发送更多请求…
目前,我唯一的想法是在我的代码运行之前发送“确定”答案,这对我来说似乎不正确(而且我不知道如何做TBH)。因此,请指出正确的方向如何处理这些情况。
I built a simple telegram bot that runs on Google Cloud Functions. My webhook looks like this:
def webhook(request):
bot = telegram.Bot(token=os.environ["TELEGRAM_TOKEN"])
if request.method == "POST":
update = telegram.Update.de_json(request.get_json(force=True), bot)
#my code calls functions in here
return "ok"
The problem at this point is that my code takes too long to run, which causes either Telegram or Google Cloud (haven’t quite figured that out yet) to resend the request, creating more instances, sending more requests …
My only idea at this point would be to send the „ok“ answer before my code runs, which doesn‘t seem right to me (and I don‘t know how to do tbh). So please point me in the right direction on how to deal with these situations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论