Skip to content
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

Bad request when sending message to group chat #210

Open
IMozgg opened this issue Aug 28, 2021 · 0 comments
Open

Bad request when sending message to group chat #210

IMozgg opened this issue Aug 28, 2021 · 0 comments
Assignees
Labels

Comments

@IMozgg
Copy link

IMozgg commented Aug 28, 2021

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:
@ableev ableev added the bug label Dec 21, 2022
@ableev ableev self-assigned this Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants