New Telegram bot return almost empty JSON to API
Asked Answered
S

8

17

I want to create a Telegram bot, so I followed the instructions and got:

Done! Congratulations on your new bot. You will find it at t.me/RonGuruBot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.

Use this token to access the HTTP API: 318659684:AAFdR9YE4DEwg1NQitSIuifPotoA-3f6cUw

However, when I enter the following URL into Chrome:

https://api.telegram.org/bot318659684:AAFdR9YE4DEwg1NQitSIuifPotoA-3f6cUw/getUpdates

The returned JSON is:

{"ok":true,"result":[]}

And the documentation led me to believe that there should be more in the JSON reply.

  • Should there be more?
  • What should I change to get a correct JSON reply?
Slipstream answered 9/5, 2017 at 21:35 Comment(3)
You should probably regenerate that token now, as that's used to control your bot and you just posted it online to hundreds of people :PDialyse
I'm just 'feeling the waters', so don't really care. I'm aware of the /token command. Thanks for the heads-up, @Hoi_A. Any insights into my actual questions?Slipstream
David's answer should be enough tbh. Your resulted JSON is completely fine and to be expected as there can't be an Updates object for you to receive if nothing has happened yet. Also since "ok" is true that means the request was correct as per the API DocumentationDialyse
L
10

if you do not change the privacy settings,

the bot only receives messages beginning with / e.g. /start,

this can be painful research, especially in multi-user chats

a good strategy is to mention the bot in the group

(e.g. /start @mybot_bot )

Limnology answered 31/5, 2020 at 20:48 Comment(0)
R
5

I think the issue is about initiating first updates to the bot via Desktop app. When I sent a message to bot from my mobile app, I started to receive updates.

Richia answered 24/4, 2020 at 21:15 Comment(0)
E
3

every thing is fine. your bot didn't receive any updates. i sent a message to your bot and if you fetch the updates again you can see that.

Editorial answered 10/5, 2017 at 3:8 Comment(0)
M
3

Albeit from 2017, this still pops up as one of the first results in Google and it is still relevant so ... in my case :

  1. Send a message to the just created bot (like hello) just after the /start command
  2. execute getUpdates again
Momism answered 16/8, 2020 at 21:25 Comment(0)
S
1

Is it running on telegram server or somewhere else? I had the same issue. When I removed script from own server it started to give updates.

Sequester answered 7/9, 2019 at 12:15 Comment(0)
A
1

I had the same problem with that. It seems that the parameter offset that is mentioned as optional in the doc, is not so and response will be empty without specifying that. I could solve the problem by setting offset=0.

Adamek answered 17/3, 2020 at 8:43 Comment(0)
Y
0

check bot settings about Webhook https://api.telegram.org/bot<your_token>/getWebhookInfo , because getUpdates method will not work if an outgoing webhook is set up (see documentation).

if you have an error similar like this:

raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=50)

you should add parameter timeout to getUpdates method (see documentation about it)

Yesman answered 3/12, 2018 at 11:18 Comment(0)
M
0

I have created a simple test bot and in the "Start" command I have put the following:

def start(update, context):
    print("CHAT ID: "+str(update.message.chat_id))

You execute the .py and then send /start command by telegram APP

Motif answered 5/2, 2022 at 12:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.