Search code examples
pythonmessagemediatelethon

How to add both image and title while answering to an inline query?


I am using the telethon library for my telegram bot, and I am struggling with how to add both image and title in an inline query handler.

Right now I am using the following code:

await event.answer([builder.photo(path_to_local_jpeg_file, text='text', include_media=False)])

It works fine with my jpeg file, but when I make the inline query it is marked as "Untitled". An attribute title, which would seem logical, is invalid.


Solution

  • Here is the solution. The jpeg file has to stored externally.

        photo = types.InputWebDocument(
                url=url,
                size=0,
                mime_type="image/jpeg",
                attributes=[],
            )
        title = "title"
        await event.answer([
            builder.article(title, text=title, thumb=photo, content=photo)
        ])