3

On Telegram, every group has a chat-id that my bot saves whenever it is added to a group.

If an owner of a group converts it to a supergroup, will the ID of the group change? And if it does, how can we get the new chat-id for the group?


I've looked for this all over the internet without success, so I'm asking here to self-answer to help people looking for this in the future, saving them the time trial and error took me.

confetti
  • 1,062
  • 2
  • 12
  • 27

1 Answers1

2

After testing it out for myself, the chat-id does change on migration to a supergroup.

However I found the following way, using python-telegram-bot to keep your chat-ids updated:

def migchat(bot, update):
  oldchatid = update.message.migrate_from_chat_id
  newchatid = update.message.chat.id
  # process those values as needed (e.g. update a database)

dispatcher.add_handler(MessageHandler(Filters.status_update.migrate, migchat))

This uses the Filters submodule to call migchat whenever a chat is being migrated.

This is how the JSON response of the message from the /getUpdates call looks like: API response

confetti
  • 1,062
  • 2
  • 12
  • 27