0

Anyone knows how to edit entities in pyrogram? Below is a test script that I'm using, I just wanted to edit the 'url' entity of the message thru code but I'm getting an error on utils.py module:

CODE:

    async with Client("tg") as tg:
        await tg.edit_message_text(
            chat_id=board_id,
            message_id=123,
            text="Happy Birthday!",
            entities=[
                {
                    "_": "MessageEntity",
                    "type": "MessageEntityType.TEXT_LINK",
                    "offset": 0,
                    "length": 15,
                    "url": "https://t.me/c/1234567890/123"
                },
            ]
        )
  File "C:\Users\tito\maya\pythonProject1\lib\site-packages\pyrogram\methods\utilities\run.py", line 77, in run
    run(coroutine)
  File "C:\Users\tito\.pyenv\pyenv-win\versions\3.10.7\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Users\tito\pythonProject1\test2.py", line 45, in main
    await tg.edit_message_text(
  File "C:\Users\tito\maya\pythonProject1\lib\site-packages\pyrogram\methods\messages\edit_message_text.py", line 88, in edit_message_text
    **await utils.parse_text_entities(self, text, parse_mode, entities)
  File "C:\Users\tito\maya\pythonProject1\lib\site-packages\pyrogram\utils.py", line 350, in parse_text_entities
    entity._client = client
AttributeError: 'dict' object has no attribute '_client'

Process finished with exit code 1
jtrner
  • 1
  • 1

1 Answers1

0

You cannot manually add or edit Message Entities. You can, however, use Markdown or HTML to add styling to your messages.

with Client() as app:
    app.send_message(
        text="[Link as Markdown](https://example.com)"
    )
    app.send_message(
        text="<a href='https://example.com'>Link as HTML</a>"
    )
ColinShark
  • 1,047
  • 2
  • 10
  • 18
  • I see.. I thought it would be possible, since there is an "entities" parameter on edit_message_text() method. – jtrner Aug 05 '23 at 18:46
  • I have to edit the text message somehow. Sometimes, the hyperlink url of the text message has to change to a different one. So only way to do it, is to copy the old message, edit the url and re-send it again? – jtrner Aug 05 '23 at 18:54