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 respective IDs. The bot should be able to collect this information and send it back to me.

Currently my bot can handle basic operations like sending regular messages and even processing payments through sendInvoice functionality. However I’m struggling with implementing the messages.getAllChats method properly.

The official documentation seems unclear to me and most code samples I found are written in languages like Lua or PHP. I’m planning to implement this using Node.js but I’m not completely confident about the approach.

Can someone guide me on how to properly use this method to fetch chat data? Any working examples would be really helpful.

Had this exact problem six months ago building a customer support bot. elizabeths is right - you can’t retrieve existing chats through Bot API. What’s annoying is Telegram’s docs don’t mention this limitation clearly. I wasted days trying different approaches before figuring out the restriction. My solution was a simple SQLite database that grabs chat IDs when users send their first message. I use /start to trigger storing new chat_id values with timestamps. It’s been running smooth in production and does exactly what I need without dealing with MTProto complexity. The trick is switching from pulling data to collecting it as interactions happen.

yeah, that bot api limitation is annoying when you hit it. i switched to webhooks instead of polling - whenever someone messages the bot, i just save their chat_id to a json file. works great for smaller projects and you don’t need a database like sqlite unless you’re dealing with tons of users.

You’re mixing up Telegram’s Bot API with the Client API. The messages.getAllChats method you mentioned is part of MTProto Client API, not the Bot API that most people use for bots. Regular Bot API doesn’t let bots get a list of all their chats - this is intentional for privacy and security. Bots can only work with chats where users explicitly started conversations or added the bot. If you really need this feature, you’d have to use Telegram’s MTProto protocol with libraries like GramJS or telegram-mtproto for Node.js. But that requires user authentication (not bot auth) and brings extra complexity plus rate limits. For most bots, just store chat IDs in your own database as users interact with your bot instead of trying to pull them from Telegram’s servers.