ableev / ableev/Zabbix-in-Telegram

Bad request when sending message to group chat

Aperta
#210 0 commenti 0 reazioni 1 assegnatario Rivendicata da @ableev Vedi su GitHub
bug
Lingua principale
Python
Stelle
815
Fork
236
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hello, I have a problem with sending a message to a group chat. Some times ago after created the group chat a function of sending a message then it returned an error message: "Bad Request: group chat was upgraded to a supergroup chat".
I review the code zbxtg.py and found a mistake these **if tg.error.find("migrated") > -1 and tg.error.find("supergroup") > -1**:

```
if not is_single_message:
tg.send_message(uid, zbxtg_body_text)
if not tg.ok:
# first case – if group has been migrated to a supergroup, we need to update chat_id of that group
**if tg.error.find("migrated") > -1 and tg.error.find("supergroup") > -1:**
#if tg.result["description"].find("supergroup chat") > -1:
migrate_to_chat_id = tg.result["parameters"]["migrate_to_chat_id"]
tg.update_cache_uid(zbx_to, migrate_to_chat_id, message="Group chat is migrated to supergroup, "
"updating cache file")
uid = migrate_to_chat_id
tg.send_message(uid, zbxtg_body_text)

# another case if markdown is enabled and we got parse error, try to remove "bad" symbols from message
if tg.markdown and tg.error.find("Can't find end of the entity starting at byte offset") > -1:
markdown_warning = "Original message has been fixed due to {0}. " \
"Please, fix the markdown, it's slowing down messages sending."\
.format(url_wiki_base + "/" + settings_description["markdown"]["url"])
markdown_fix_attempts = 0
while not tg.ok and markdown_fix_attempts != 3:
offset = re.search("Can't find end of the entity starting at byte offset ([0-9]+)", tg.error).gr$
zbxtg_body_text = markdown_fix(zbxtg_body_text, offset, emoji=internal_using_emoji) + \
["\n"] + [markdown_warning]
tg.disable_web_page_preview = True
tg.send_message(uid, zbxtg_body_text)
markdown_fix_attempts += 1
if tg.ok:
print_message(markdown_warning)
```

In my opinion, the error code of the Telegram API was changed, but it was not in code. That's why I updated key find words from 'migrated' to '_upgraded_' then it worked for me.

```
if tg.error.find("upgraded") > -1 and tg.error.find("supergroup") > -1:
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.