我将setWebhook用于我的电报机器人,现在我需要使用getUpdates。我已经阅读了文档,他们说我只能使用一种方法。
问题是,我在控制台中有:
{"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"}
所以问题是,如何取消设置webhook并使用getUpdates?
我将setWebhook用于我的电报机器人,现在我需要使用getUpdates。我已经阅读了文档,他们说我只能使用一种方法。
问题是,我在控制台中有:
{"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"}
所以问题是,如何取消设置webhook并使用getUpdates?
在浏览器中发送以下请求:
https://api.telegram.org/bot655390656:bhFS50...ff3zO4/setwebhook
如 Telegram bot api 文档中所述,您只需将空字符串传递给url
参数。
> base_url = 'https://api.telegram.org/bot' + TOKEN + '/'
> data = {"url": ""}
> requests.post(base_url + 'setWebhook', data=data)
你可以调用该方法
deleteWebhook()
https://core.telegram.org/bots/api#deletewebhook
例如使用 Telepot
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]