Skip to content

Commit eee5bf2

Browse files
author
Pietro Albini
committed
Merge branch 'bugfix/72'
2 parents d7c6fd8 + b21378c commit eee5bf2

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

botogram/api.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,47 @@ def call(self, method, params=None, files=None, expect=None):
104104
# Special handling for unavailable chats
105105
if method in SEND_TO_CHAT_METHODS:
106106
reason = None
107+
108+
# This happens when the bot tries to send messages to an user
109+
# who blocked the bot
107110
if status == 403 and "blocked" in message:
111+
# Error code # 403
112+
# Bot was blocked by the user
108113
reason = "blocked"
109-
elif status == 403 and "deleted user" in message:
114+
115+
# This happens when the user deleted its account
116+
elif status == 403 and "deleted" in message:
117+
# Error code # 403
118+
# Forbidden: user is deleted
110119
reason = "account_deleted"
120+
121+
# This happens, as @BotSupport says, when the Telegram API
122+
# isn't able to determine why your bot can't contact an user
111123
elif status == 400 and "PEER_ID_INVALID" in message:
112-
# What, this error is an identifier and not a sentence :/
124+
# Error code # 400
125+
# PEER_ID_INVALID
113126
reason = "not_contacted"
127+
128+
# This happens when the bot can't contact the user or the user
129+
# doesn't exist
114130
elif status == 400 and "not found" in message:
131+
# Error code # 400
132+
# Bad Request: chat not found
115133
reason = "not_found"
134+
135+
# This happens when the bot is kicked from the group chat it's
136+
# trying to send messages to
116137
elif status == 403 and "kicked" in message:
138+
# Error code # 403
139+
# Forbidden: bot was kicked from the group chat
140+
# Forbidden: bot was kicked from the supergroup chat
117141
reason = "kicked"
118-
elif status == 400 and "deactivated" in message:
142+
143+
# This happens when the ID points to a group chat, which was
144+
# migrated to a supergroup chat, thus changing its ID
145+
elif status == 400 and "migrated" in message:
146+
# Error code # 400
147+
# Bad Request: group chat is migrated to a supergroup chat
119148
reason = "chat_moved"
120149

121150
if reason is not None:

docs/changelog/0.3.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ Changelog of botogram 0.3.x
77

88
Here you can find all the changes in the botogram 0.3.x releases.
99

10+
.. _changelog-0.3.3:
11+
12+
botogram 0.3.3
13+
==============
14+
15+
*Bugfix release, not yet released*
16+
17+
* Fix broken detection of unavailable chats, due to changes in the Bot API
18+
(`issue 72`_)
19+
20+
.. _issue 72: https://github.com/pietroalbini/botogram/issues/72
21+
1022
.. _changelog-0.3.2:
1123

1224
botogram 0.3.2

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)