Skip to content

Commit f1ee54f

Browse files
overquotatsnoam
authored andcommitted
ChatMigrated exception (python-telegram-bot#353)
* ChatMigrated exception
1 parent 9091372 commit f1ee54f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The following wonderful people contributed directly or indirectly to this projec
2222
- `njittam <https://github.com/njittam>`_
2323
- `Noam Meltzer <https://github.com/tsnoam>`_
2424
- `Oleg Shlyazhko <https://github.com/ollmer>`_
25+
- `overquota <https://github.com/overquota>`_
2526
- `Rahiel Kasim <https://github.com/rahiel>`_
2627
- `Shelomentsev D <https://github.com/shelomentsevd>`_
2728
- `sooyhwang <https://github.com/sooyhwang>`_

telegram/error.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ class TimedOut(NetworkError):
8585

8686
def __init__(self):
8787
super(TimedOut, self).__init__('Timed out')
88+
89+
90+
class ChatMigrated(TelegramError):
91+
92+
def __init__(self, new_chat_id):
93+
"""
94+
Args:
95+
new_chat_id (int):
96+
97+
Returns:
98+
99+
"""
100+
super(ChatMigrated, self).__init__('Chat migrated')
101+
self.new_chat_id = new_chat_id

telegram/utils/request.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from urllib3.connection import HTTPConnection
2929

3030
from telegram import (InputFile, TelegramError)
31-
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest
31+
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated
3232

3333
_CON_POOL = None
3434
""":type: urllib3.PoolManager"""
@@ -135,8 +135,15 @@ def _parse(json_data):
135135
except ValueError:
136136
raise TelegramError('Invalid server response')
137137

138-
if not data.get('ok') and data.get('description'):
139-
return data['description']
138+
if not data.get('ok'):
139+
description = data.get('description')
140+
parameters = data.get('parameters')
141+
if parameters:
142+
migrate_to_chat_id = parameters.get('migrate_to_chat_id')
143+
if migrate_to_chat_id:
144+
raise ChatMigrated(migrate_to_chat_id)
145+
if description:
146+
return description
140147

141148
return data['result']
142149

0 commit comments

Comments
 (0)