Skip to content

InlineQueryResultPhoto: Pass image bytes instead of URL #1557

Answered by xk4rimx
xk4rimx asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you, @Badiboy. I discovered that input_message_content requires a URL yesterday and forgot to update this question.
After hours of digging, I finally found a workaround:

  1. Send the photo to a private channel made solely for caching.
  2. Retrieve the photo to answer the inline query.
  3. Delete the photo in the caching channel.
msg = bot.send_photo(chat_id=CACHE_CHANNEL_ID, photo=image)
photo_file_id = msg.photo[0].file_id

option = InlineQueryResultCachedPhoto(
                    id='0',
                    title=title,
                    description=description,
                    photo_file_id=photo_file_id,
                    caption=caption,
                    parse_mode='MARKDOWN'

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by xk4rimx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants