atipugin / telegram-bot-ruby

Ruby wrapper for Telegram's Bot API

Home Page:https://core.telegram.org/bots/api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad Request: group chat was upgraded to a supergroup chat

marckohlbrugge opened this issue · 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?

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.

Message has #migrate_to_chat_id attribute

@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 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 :)