-
Notifications
You must be signed in to change notification settings - Fork 5.8k
ChatMigrated exception #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if not data.get('ok') and data.get('description'): | ||
return data['description'] | ||
if not data.get('ok'): | ||
if data.get('parameters') and data['parameters'].get('migrate_to_chat_id'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(edited)
please save data.get('parameters')
into a variable, so you won't need to get it 3 times. same goes for migrate_to_chat_id
.
@overquota 1 Please see the comments I've put on the code. |
Hi! Thank you for comments! |
if migrate_to_chat_id: | ||
raise ChatMigrated(description, chat_id=int(migrate_to_chat_id)) | ||
else: | ||
return description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above code is correct with the JSON reply.
However, it is better to be more liberal with the way we interpret the replies from Telegram servers, especially that they like making changes without any prior notification.
So... please do something more similar to your original commit:
if parameters:
if migrate... :
raise
if description:
return description
Hi @overquota , |
Hmm, last change breaked CI, but I can't reproduce it:
|
Seems like CI failing on some temp reasons (timeout?) |
@overquota thanks for your work! Our Travis tests sometimes fail for no good reason, but they're all good now. @tsnoam, time to merge? |
When converting telegram group (OLD_CHAT_ID) to supergroup (NEW_CHAT_ID), chat id changes
After this, when trying to post message to OLD_CHAT_ID, Telegram API returns error with message:
{u'error_code': 400, u'ok': False, u'description': u'Bad Request: group chat is migrated to a supergroup chat', u'parameters': {u'migrate_to_chat_id': NEW_CHAT_ID}}
So this pull requests creates new exception ChatMigrated which returns NEW_CHAT_ID
With this functionality we can postpone fix our inconsistency data in database when user converts group to supergroup and we cannot update this info in database at the same time (eg datacenter failed or network lag)
Sorry for my English :)