telegram-bot-ruby icon indicating copy to clipboard operation
telegram-bot-ruby copied to clipboard

Bad Request: group chat was upgraded to a supergroup chat

Open marckohlbrugge opened this issue 3 years ago • 4 comments

When a regular group is upgraded to a supergroup chat it gets a new chat ID. Unfortunately that means the former chat ID is no longer usable and will just return a Bad Request: group chat was upgraded to a supergroup chat exception.

How can we get this new chat ID?

From what I read online, Telegram responds with the new chat ID (migrate_to_chat_id) when trying to use the old one. However, I can't find a way to access this ID through this gem.

Does telegram-bot-ruby expose this migrate_to_chat_id value in any way?

marckohlbrugge avatar Oct 21 '21 14:10 marckohlbrugge

How did you try to access migrate_to_chat_id from a response? As far as I know we don't do anything special with responses, just parse them in JSON.

ivanovaleksey avatar Oct 22 '21 06:10 ivanovaleksey

Message has #migrate_to_chat_id attribute

atipugin avatar Oct 22 '21 06:10 atipugin

@ivanovaleksey I'm not sure how to access it. When I try to send a message it throws the exception I should be using the new chat ID. So my question is how to get the chat ID?

@atipugin Ah yes I saw that. If there's a new incoming message I could use that. But what if I want to initiate sending a message after the upgrade? There's no Message object to refer to then to get this new chat ID.

marckohlbrugge avatar Oct 22 '21 10:10 marckohlbrugge

@marckohlbrugge Oh, got you. Looks like you can try to catch ResponseError and parse e.response.body field. As far i understand in case of upgraded group response body will contain parameters.migrate_to_chat_id key.

There's also ResponseError#data method, which does basically the same thing, but for now it's declared as private. Maybe it's time to expose it to public :)

atipugin avatar Oct 22 '21 11:10 atipugin