How to use getUpdates after setWebhook in Telegram Bot API
Asked Answered
T

4

7

I use setWebhook for my telegram-bot and now I need to use getUpdates. I have read the docs, and they say, that I can use only one method.

The problem is, that I have in console:

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

So the question is, how to UNSET webhook and use getUpdates?

Theurich answered 12/9, 2015 at 9:6 Comment(0)
P
11

as mentioned in Telegram bot api documentations you just need to pass empty string to url parameter.

> base_url = 'https://api.telegram.org/bot' + TOKEN + '/'
> data = {"url": ""}
> requests.post(base_url + 'setWebhook', data=data)
Playsuit answered 12/9, 2015 at 9:27 Comment(0)
B
13

In a browser send the following request:

https://api.telegram.org/bot655390656:bhFS50...ff3zO4/setwebhook
Benevento answered 2/7, 2016 at 1:41 Comment(1)
most useful answerMcgraw
P
11

as mentioned in Telegram bot api documentations you just need to pass empty string to url parameter.

> base_url = 'https://api.telegram.org/bot' + TOKEN + '/'
> data = {"url": ""}
> requests.post(base_url + 'setWebhook', data=data)
Playsuit answered 12/9, 2015 at 9:27 Comment(0)
J
0

you can just call the method

deleteWebhook()

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

for example using telepot

import telepot
bot = telepot.Bot('YOUR_AUTHORIZATION_TOKEN')
bot.deleteWebhook()
Joycelynjoye answered 5/7, 2017 at 0:23 Comment(0)
D
0

I wrote a small rake task for this job

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

If you have the token stored in the credentials you can get them via: token = Rails.application.credentials.telegram[:bot]

Deville answered 30/12, 2018 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.