Python Telegram bot‘ s Webhook进入无限循环

发布于 2025-01-20 11:18:26 字数 494 浏览 1 评论 0原文

我构建了一个简单的电报机器人,该机器人在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文