pyTelegramBotAPI icon indicating copy to clipboard operation
pyTelegramBotAPI copied to clipboard

Troubles sending image in inline mode.

Open BigDanTheOne opened this issue 3 years ago • 10 comments

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? 4.6.0
  2. What OS are you using? Mac Os
  3. What version of python are you using? 3.7.11

Hello, I'm using inline bot and trying to print a photo, which is already on a telegram server. But when I pass it's file id id = 'AgACAgIAAxkBAAIkc2LB6mYy0GnZBzKTXuxG_2qCaQAB2wACkr4xG8AuEEqrRCYAAUPEFEMBAAMCAANzAAMpBA' to either InlineQueryResultCachedPhoto like

types.InlineQueryResultCachedPhoto('2', photo_file_id=id, title='title', description='description', caption='caption')

or InlineQueryResultPhoto like

types.InlineQueryResultPhoto('2', photo_url=id, thumb_url=id, title='title', description='description', caption='caption')

I get "Untitled" instead of the description image

But when I pass a random url from the web everything works as expected: image What should I do to fix this?

BigDanTheOne avatar Jul 22 '22 16:07 BigDanTheOne

Can you please provide whole code to reproduce this issue?

coder2020official avatar Jul 22 '22 16:07 coder2020official

@tb.inline_handler(lambda query: query.query)
async def query_text(inline_query):
        r1 = types.InlineQueryResultArticle('1', 'Result', types.InputTextMessageContent('Result message.'))
        r2 = types.InlineQueryResultArticle('2', 'Result2', types.InputTextMessageContent('Result message2.'))
        id='AgACAgIAAxkBAAIkc2LB6mYy0GnZBzKTXuxG_2qCaQAB2wACkr4xG8AuEEqrRCYAAUPEFEMBAAMCAANzAAMpBA' 
        r3 = types.InlineQueryResultCachedPhoto('3', photo_file_id=id, 
                                          title='title', description='description', caption='caption')
        await tb.answer_inline_query(inline_query.id, [r1, r3, r2], cache_time=0)
   

BigDanTheOne avatar Jul 22 '22 16:07 BigDanTheOne

You should pass a title for InlineQueryResultArticle objects. https://core.telegram.org/bots/api#inlinequeryresultarticle

coder2020official avatar Jul 22 '22 16:07 coder2020official

@coder2020official But if I pass a title to InlineQueryResultPhoto and a random url from the web everything works fine

@tb.inline_handler(lambda query: query.query)
async def query_text(inline_query):
        r1 = types.InlineQueryResultArticle('1', 'Result', types.InputTextMessageContent('Result message.'))
        r2 = types.InlineQueryResultArticle('2', 'Result2', types.InputTextMessageContent('Result message2.'))
        url = 'https://kudago.com/media/images/event/1a/f1/1af1f99cdcfe824ddd8e9ffb14afde8b.jpg'
        r3 = types.InlineQueryResultPhoto('3', photo_url=url, thumb_url=url,
                                          title='title', description='description', caption='caption')
        await tb.answer_inline_query(inline_query.id, [r1, r3, r2], cache_time=0)
image

BigDanTheOne avatar Jul 22 '22 17:07 BigDanTheOne

I didn't get your issue. You should always pass title cuz it is not optional.

coder2020official avatar Jul 22 '22 17:07 coder2020official

-You should always pass title cuz it is not optional. Yes, sure. -I didn't get your issue Don't you have "Untitled" passing id of a photo stored on the Telegram servers (not a random url from the web) to InlineQueryResultCachedPhoto? Do you get your title? Could you please show screens/code snippets with the photo id.

BigDanTheOne avatar Jul 22 '22 17:07 BigDanTheOne

So you are having untitled title for random image from internet?

coder2020official avatar Jul 24 '22 18:07 coder2020official

So you are having untitled title for random image from internet?

No. For a random image from internet everything is ok. I have untitled only for an image stored on the Telegram servers

BigDanTheOne avatar Jul 25 '22 00:07 BigDanTheOne

image Here is the output when i run your code. The title isn't displayed, only image is displayed.

coder2020official avatar Jul 26 '22 15:07 coder2020official

Still struggling?

coder2020official avatar Aug 10 '22 13:08 coder2020official

No, thanks a lot.

BigDanTheOne avatar Aug 12 '22 10:08 BigDanTheOne

image Here is the output when i run your code. The title isn't displayed, only image is displayed.

I'm faced the very same issue. So in this particular example why the phot doesn't have neither title nor description regardless they were provided?

Why the behavior is not consistent among ResultPhoto and ResultCachedPhoto regardless the similar call attributes set

Can someone clarify the behavior please?

@BigDanTheOne What was your resolution on the subject?

kudla avatar Oct 19 '22 20:10 kudla

Solution?

PraryDogy avatar Jan 07 '23 19:01 PraryDogy