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

send_media_group() fucntion cannot parse caption_entities set manually #765

Open
3 tasks done
Makiras opened this issue Oct 6, 2021 · 3 comments · May be fixed by #1253
Open
3 tasks done

send_media_group() fucntion cannot parse caption_entities set manually #765

Makiras opened this issue Oct 6, 2021 · 3 comments · May be fixed by #1253

Comments

@Makiras
Copy link

Makiras commented Oct 6, 2021

Checklist

  • I am sure the error is coming from Pyrogram's code and not elsewhere.
  • I have searched in the issue tracker for similar bug reports, including closed ones.
  • I ran pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip and reproduced the issue using the latest development version.

Description

send_media_group does not recognition caption_entities which were set manually. The bold and text_link func doesn't work.
However the same entities works on send_message.

( I think the hashtag and mention style is parse by client)

image

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from pyrogram import Client
from pyrogram.handlers import MessageHandler
from pyrogram.types import InputMediaPhoto, InputMediaVideo, MessageEntity


def dump(client, message):
    client.send_media_group(
        "id",
        [
            InputMediaPhoto(
                "AgACAgUAAxkBAAMUYV1DlFpUU2l4mVUkm3iKFVSL2_UAAqisMRsxnuhWQrSoLt_ra2uc9_d5dAADAQADAgADeQADMCQAAh4E",
                caption="#测试 #继续测试 #还是测试\n没有什么 @Makiras 解决\n还是算了吧",
                parse_mode=None, # I have tried "md", "html", None and remove this field
                caption_entities=[
                    MessageEntity(type="hashtag", offset=0, length=3),
                    MessageEntity(type="hashtag", offset=4, length=5),
                    MessageEntity(type="hashtag", offset=10, length=5),
                    MessageEntity(type="mention", offset=21, length=8),
                    MessageEntity(type="bold", offset=30, length=3),
                    MessageEntity(type="text_link", offset=33,
                                  length=5, url="https://baidu.com/"),
                ]
            ),
            InputMediaPhoto(
                "AgACAgUAAxkBAAMTYV1DlB0-q5pQKYKWII1t_oahUOwAAqesMRsxnuhW8vM97N_gmdu7t3VzdAADAQADAgADeQADdF0FAAEeBA",
            ),

        ]
    )
    client.send_message(
        "id",
        "#测试 #继续测试 #还是测试\n没有什么 @Makiras 解决\n还是算了吧",
        entities=[
            MessageEntity(type="hashtag", offset=0, length=3),
            MessageEntity(type="hashtag", offset=4, length=5),
            MessageEntity(type="hashtag", offset=10, length=5),
            MessageEntity(type="mention", offset=21, length=8),
            MessageEntity(type="bold", offset=30, length=3),
            MessageEntity(type="text_link", offset=33,
                          length=5, url="https://baidu.com/"),
        ]

    )
    print("Message sent.")

bot = Client(
    "my_bot",
    api_id="",
    api_hash="",
    bot_token="",
    sleep_threshold=4,
    proxy=dict(hostname="127.0.0.1", port=1080)
)

bot.add_handler(MessageHandler(dump))

bot.run()

...

Traceback

NONE

@barsikus007
Copy link

barsikus007 commented Apr 9, 2023

This bug still exists
pyrogram/methods/messages/send_media_group.py:389 have the outdated parser call
If you change that line to

**await utils.parse_text_entities(self, i.caption, i.parse_mode, i.caption_entities)

and it will work as intended

I will make PR for that

@Polikanov63
Copy link

The developers still haven’t fixed this bug. Thank you, @barsikus007!

@kradt
Copy link

kradt commented Mar 22, 2024

I have the same issue and should admit that when I use send_media_group on Windows 10, it works well.
But when I do the same on Ubuntu 20.04, send_media_group does not see all MessageEntity.
Does anyone know how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants