【问题标题】:How to use getUpdates after setWebhook in Telegram Bot API如何在 Telegram Bot API 中的 setWebhook 之后使用 getUpdates
【发布时间】:2015-12-08 19:38:41
【问题描述】:

我为我的电报机器人使用 setWebhook,现在我需要使用 getUpdates。我已阅读文档,他们说我只能使用一种方法。

问题是,我在控制台中:

{"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"}

那么问题来了,如何UNSET webhook 和使用getUpdates?

【问题讨论】:

    标签: telegram telegram-bot


    【解决方案1】:

    如 Telegram bot api 文档中所述,您只需将空字符串传递给 url 参数。

    > base_url = 'https://api.telegram.org/bot' + TOKEN + '/'
    > data = {"url": ""}
    > requests.post(base_url + 'setWebhook', data=data)
    

    【讨论】:

      【解决方案2】:

      在浏览器中发送以下请求:

      https://api.telegram.org/bot655390656:bhFS50...ff3zO4/setwebhook
      

      【讨论】:

      • 最有用的答案
      【解决方案3】:

      你可以直接调用方法

      deleteWebhook()
      

      https://core.telegram.org/bots/api#deletewebhook

      例如使用 Telepot

      import telepot
      bot = telepot.Bot('YOUR_AUTHORIZATION_TOKEN')
      bot.deleteWebhook()
      

      【讨论】:

        【解决方案4】:

        我为这个工作写了一个小耙任务

        require 'net/https'
        
        namespace :telegram_custom do
          desc "Deactives webhook - this is needed to enable polling in development"
          task deactivate_webhook: :environment do
            token = "YOUR_BOT_TOKEN"
            base_url = "https://api.telegram.org/bot#{token}/setwebhook"
            uri = URI.parse(base_url)
        
            res = Net::HTTP.get URI(base_url)
            puts res
          end
        end
        

        如果您将令牌存储在凭据中,您可以通过以下方式获取它们:token = Rails.application.credentials.telegram[:bot]

        【讨论】:

          猜你喜欢
          • 2021-11-26
          • 2015-10-22
          • 2017-12-17
          • 1970-01-01
          • 2017-02-23
          • 2020-09-15
          • 1970-01-01
          • 1970-01-01
          • 2021-11-02
          相关资源
          最近更新 更多