How to retrieve all chat conversations with IDs using Telegram Bot API

I’m working on a Telegram bot project and need help with fetching all my chat conversations along with their unique identifiers. The official API docs are pretty confusing and most examples I found are written in languages like PHP or Lua which doesn’t help much.

My bot already works fine for basic stuff like sending regular messages and creating invoices with sendInvoice method. But I’m stuck on implementing the messages.getAllChats functionality.

I’m planning to use Node.js for this but not completely sure if that’s the right approach. Has anyone worked with this specific API method before? Any code examples or guidance would be really helpful.

Yep, that’s right - Bot API doesn’t let you pull all chats directly. I ran into this same problem last year and ended up building a simple logging system. Every time someone messages my bot, I grab their chat ID and throw it in a database with a timestamp and user details. You can use getUpdates to poll for new messages and pull the chat IDs from there. If you’re using Node.js, node-telegram-bot-api works great for this. Just keep in mind bots are pretty limited - you can only see chats where your bot’s actually been added and has gotten at least one message.

i think you’re mistaken, there isn’t a getAllChats method in the telegram bot api. bots can only access chats where users have messaged them first. maybe try storing chat ids in a db when they initiate convos? good luck!

Hit this same problem 6 months back building a support bot. Everyone’s right - there’s no way to fetch all chats directly. I switched to webhooks instead of getUpdates polling, which handles incoming messages way better in real-time. Every time someone messages the bot, I grab their chat_id and dump it into MongoDB with username and first contact date. Just heads up - you’ll miss chats from users who haven’t messaged recently if you’re starting this logging now. For Node.js, go with telegraf over node-telegram-bot-api. Way more intuitive for different message types and keeping track of chat state.