Why isn't my Telegram inline bot showing results despite successful API response?

Hey everyone! I’m struggling with my Telegram inline bot. It’s weird because the API says everything’s fine, but no results show up when I use it. The bot even gives me the ‘switch to PM’ button, so it’s kinda working?

I think the problem might be how I’m setting up the results array. Here’s a simplified version of what I’m doing:

bot.on_inline_query do |query|
  results = [
    {type: 'article', id: '1', title: 'First Option', message_text: 'You picked the first option'},
    {type: 'article', id: '2', title: 'Second Option', message_text: 'You chose the second option'}
  ]
  
  bot.answer_inline_query(query.id, results, cache_time: 1.day)
end

Can anyone spot what I’m doing wrong? Or suggest a better way to handle this? I’m totally stuck!

I experienced a similar issue recently and discovered that the problem wasn’t with the API response itself but how the result data was being handled. In my case, I realized that even minor oversights like a mistyped token or missing secure HTTPS calls could affect the display of results. I opted to add extra descriptive details into my result objects, which surprisingly contributed to resolving the issue. Additionally, I implemented logging for the API responses to catch subtle errors in the data structure. This approach ultimately led to the inline results appearing as expected.

hey mate, had same prob before. check ur bot settings in botfather, make sure inline mode is on. also, try adding a description to ur results like this:

results = [
{type: ‘article’, id: ‘1’, title: ‘First Option’, description: ‘Pick this one’, message_text: ‘You picked the first option’},

… rest of ur code

]

hope this helps!

I’ve encountered a similar issue before. The problem might be in how you’re structuring the results array. Telegram expects a specific format for inline query results. Try modifying your code to use InlineQueryResultArticle objects instead of plain hashes. Here’s an example:

bot.on_inline_query do |query|
  results = [
    Telegram::Bot::Types::InlineQueryResultArticle.new(
      id: '1',
      title: 'First Option',
      input_message_content: Telegram::Bot::Types::InputTextMessageContent.new(message_text: 'You picked the first option')
    ),
    Telegram::Bot::Types::InlineQueryResultArticle.new(
      id: '2',
      title: 'Second Option',
      input_message_content: Telegram::Bot::Types::InputTextMessageContent.new(message_text: 'You chose the second option')
    )
  ]

  bot.answer_inline_query(query.id, results)
end

This structure aligns more closely with what Telegram expects. Give it a try and see if it resolves your issue.