Skip to content

Commit 0c6ae58

Browse files
author
Pietro Albini
committed
Update error messages matching for unavailable chats
This adds support for the last batch of error messages changes Telegram made, so checking for unavailable chats is reliable again. This commit also updates unit tests with more realistic testing. Fixes: GH-72
1 parent 5619fa8 commit 0c6ae58

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

botogram/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def call(self, method, params=None, files=None, expect=None):
9191
reason = None
9292
if status == 403 and "blocked" in message:
9393
reason = "blocked"
94-
elif status == 403 and "deleted user" in message:
94+
elif status == 403 and "deleted" in message:
9595
reason = "account_deleted"
9696
elif status == 400 and "PEER_ID_INVALID" in message:
9797
# What, this error is an identifier and not a sentence :/
@@ -100,7 +100,7 @@ def call(self, method, params=None, files=None, expect=None):
100100
reason = "not_found"
101101
elif status == 403 and "kicked" in message:
102102
reason = "kicked"
103-
elif status == 400 and "deactivated" in message:
103+
elif status == 400 and "migrated" in message:
104104
reason = "chat_moved"
105105

106106
if reason is not None:

tests/test_api.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,45 @@ def test_unavailable_chats(api, mock_req):
3838
mock_req({
3939
"sendMessage": {"ok": True, "result": {}},
4040
"forwardMessage": {
41-
"ok": False, "error_code": 123, "description": "test",
41+
"ok": False, "error_code": 123,
42+
"description": "This is a message!",
4243
},
4344
"sendPhoto": {
44-
"ok": False, "error_code": 403, "description": "test",
45+
"ok": False, "error_code": 403,
46+
"description": "This is not the message you want!",
4547
},
4648
"sendAudio": {
47-
"ok": False, "error_code": 123, "description": "blocked test",
49+
"ok": False, "error_code": 123,
50+
"description": "Bot was blocked by the user",
4851
},
4952
"sendDocument": {
50-
"ok": False, "error_code": 403, "description": "blocked test",
53+
"ok": False, "error_code": 403,
54+
"description": "Bot was blocked by the user",
5155
},
5256
"sendSticker": {
53-
"ok": False, "error_code": 400, "description": "chat not found",
57+
"ok": False, "error_code": 400,
58+
"description": "Bad request: chat not found",
5459
},
5560
"sendVideo": {
56-
"ok": False, "error_code": 403, "description": "I was kicked!",
61+
"ok": False, "error_code": 403,
62+
"description": "Forbidden: bot was kicked from the group chat",
5763
},
5864
"sendLocation": {
59-
"ok": False, "error_code": 400, "description": "PEER_ID_INVALID",
65+
"ok": False, "error_code": 400,
66+
"description": "PEER_ID_INVALID",
6067
},
6168
"sendVoice": {
62-
"ok": False, "error_code": 403, "description": "a deleted user",
69+
"ok": False, "error_code": 403,
70+
"description": "Forbidden: user is deleted",
71+
},
72+
"sendChatAction": {
73+
"ok": False, "error_code": 400,
74+
"description":
75+
"Bad Request: group chat is migrated to a supergroup chat",
6376
},
6477
"getMe": {
65-
"ok": False, "error_code": 403, "description": "blocked test",
78+
"ok": False, "error_code": 403,
79+
"description": "Bot was blocked by the user",
6680
},
6781
})
6882

@@ -132,7 +146,9 @@ def test_unavailable_chats_take2(api, mock_req):
132146
mock_req({
133147
"sendMessage": {"ok": True, "result": {}},
134148
"forwardMessage": {
135-
"ok": False, "error_code": 400, "description": "chat deactivated",
149+
"ok": False, "error_code": 400,
150+
"description":
151+
"Bad Request: group chat is migrated to a supergroup chat",
136152
},
137153
})
138154

0 commit comments

Comments
 (0)