Telegram 如何在电报机器人API中使用setWebhook之后的GetUpdate

Telegram 如何在电报机器人API中使用setWebhook之后的GetUpdate,telegram,telegram-bot,Telegram,Telegram Bot,我使用setWebhook作为电报机器人,现在我需要使用getUpdates。我读过文件,他们说,我只能用一种方法 问题是,我在控制台中有: {"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"} 因此,问题是,如何取消设置webhook并使用获取更新?正如Telegram bot api文档中提到的那样,您只需要将空字符串传递给url参数 > base_url =

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

问题是,我在控制台中有:

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

因此,问题是,如何取消设置webhook并使用获取更新

正如Telegram bot api文档中提到的那样,您只需要将空字符串传递给
url
参数

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

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

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

您可以调用该方法

deleteWebhook()

例如使用电传机

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

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

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]

最有用的答案