Ilya Mikheev Ilya Mikheev - 7 months ago 72
Ruby Question

I'm trying to create ruby inline bot for Telegram bot 2.0, but it shows nothing in inline result

Telegram returns me {"ok"=>true, "result"=>true} and even shows button "switch to PM", but nothing appears as the answers result. The only thing that could be broken here from my point of view is the way I'm preparing array for results to be send. Could anyone help me?

Here's code example:

Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|

case message
when Telegram::Bot::Types::Message
puts "Message @#{message.from.username}: #{message.text}"
bot.api.send_message(chat_id: message.chat.id, text: "I am only inline bot for now" )
when Telegram::Bot::Types::InlineQuery
puts " InlineQuery @#{message.from.username}: #{message.query} and #{message.id}"

results = [ JSON.parse('{"type":"article", "id":"0", "title":"Cool Blog", "message_text":"I am the author of this bot, please visit my blog"}'), JSON.parse('{"type":"article", "id":"1", "title":"Cool Blog", "message_text":"I am the author of this bot, please visit my blog"}')]
puts bot.api.answer_inline_query(inline_query_id: message.id, results: results, switch_pm_text:"PM me please", cache_time: 86400)
end

end
end

Answer

Just update gem to version '0.5' and it should work properly gem install 'telegram-bot-ruby'