andig
andig

Reputation: 13868

How can a telegram get a list of all chats he participates in?

Relates to Retrieve all chat ids using Telegram bot but 3 years later.

My use case is a bot that notifies chat participants of home automation events. Any user might create his own chat and receive events or send commands.

Currently, it seems that the bot has no option to find the chats that it participates in. Even a potential workaround like using GetUpdates(0) seems to retrieve only new message ids which makes it impossible to get a complete list of chats from looking at the received messages.

Is there a stable solution for doing this?

Upvotes: 2

Views: 3026

Answers (1)

0stone0
0stone0

Reputation: 43884

This is not possible from Telegram's API. Howerver,

A bot will receive a new_chat_members which could be the bot 'joining another group':

new_chat_members -- Array of User -- Optional.

New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)

To remember each user/group, you'll have to save each chat/user_id into a database.

The bot will also receive the opposite left_chat_member so you'll know when to delete a database entry.

Upvotes: 1

Related Questions