If you’ve ever tried to send messages via your Telegram bot but encountered this frustrating response:
{"ok":true,"result":[]}
You’re not alone. When I first ran into this, I scoured the internet, looking for a solution—because let’s face it, finding a solution for something as seemingly simple as a “chat ID” should be easier, right?
Well, after some trial and error, I finally found a way to extract the chat ID when messaging a bot, and I’m here to save you the time and effort. In this article, I’ll walk you through exactly how I solved the issue and what you can do if you’re facing the same problem.
Prerequisites
Before we dive into the solution, make sure you’ve taken care of these prerequisites:
- Created a Telegram Bot
You need a Telegram bot to interact with. If you haven’t created one yet, here’s how:- Start a chat with BotFather.
- Create your bot by following the steps provided by BotFather.
- Once created, you’ll get a token. Keep it handy—you’re going to need it.
- Added the Bot to Your Telegram Group (Optional)
If you’re trying to get the chat ID of a group, add your bot to that group and give it permissions to send messages. - Basic Knowledge of HTTP Requests
This is optional, but it’ll be useful if you want to send API requests to Telegram and get data back. Don’t worry if you’re not an expert—I’ll guide you through it.
Why We Were Seeing { "ok": true, "result": [] }
If you’re like me, the first time you tried to fetch data using the Telegram Bot API, you probably tried this:
https://api.telegram.org/bot<Your-Bot-Token>/getUpdates
But instead of the useful chat ID or a list of updates, you saw this:
{"ok":true,"result":[]}
This empty result simply means that your bot doesn’t have any messages waiting for it to respond to or, more likely, you’re not getting the right chat ID. Telegram’s API doesn’t just give you the chat ID by default—it requires you to have some interaction with the bot first.
So, How Did I Solve This?
I was stuck with the same error for a while, but eventually, the solution clicked. Here’s what I did:
1. Start a Conversation with Your Bot
This step is crucial! Without a message interaction, Telegram doesn’t know where to send the message. So, I sent a simple “Hi” to my bot. You can do this by simply opening the bot in Telegram and typing anything.
2. Use the getUpdates
API Again
Once you’ve sent a message to the bot, go back and use the getUpdates
API endpoint once more. You should now see a response with your chat ID!
Example URL to call:
https://api.telegram.org/bot<Your-Bot-Token>/getUpdates
The response will now look something like this:
{
"ok": true,
"result": [
{
"update_id": 123456789,
"message": {
"message_id": 1,
"from": {
"id": 987654321,
"first_name": "Your Name",
"last_name": "Your Last Name",
"username": "YourUsername",
"language_code": "en"
},
"chat": {
"id": 123456789, // <-- This is the chat ID!
"first_name": "Your Name",
"last_name": "Your Last Name",
"username": "YourUsername",
"type": "private"
},
"date": 1624048700,
"text": "Hi"
}
}
]
}
The key part here is the "chat": { "id": 123456789 }
. That’s your chat ID!
3. Use the Chat ID in Your Bot
Now that you have the chat ID, you can send messages to your bot via the API:
https://api.telegram.org/bot<Your-Bot-Token>/sendMessage?chat_id=123456789&text=Your%20message%20here
What If You Can’t See the Chat ID?
If you’re still not seeing your chat ID, make sure:
- You’ve sent a message to the bot first. Without that, Telegram won’t return any useful data.
- You’re checking the response right after sending a message. Sometimes there’s a delay, so give it a moment.
Final Thoughts
This process isn’t mentioned explicitly in the official Telegram documentation, which is why many of us end up feeling stuck. But by simply starting a conversation with your bot, we were able to get our chat ID and move forward with sending messages programmatically.
If you’re still encountering issues or need further assistance, feel free to leave a comment below. I hope this solution saves you the hours I spent trying to figure it out. Enjoy building your Telegram bot!