我正在尝试为 Telegram 机器人 2.0 创建 ruby 内联机器人,但它在内联结果中没有显示任何内容
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} 甚至显示按钮 "switch to PM" ,但没有出现作为答案的结果。从我的角度来看,这里唯一可以打破的是我准备数组以发送结果的方式。谁能帮帮我?
这是代码示例:
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
只需将 gem 更新到版本“0.5”,它应该可以正常工作 gem install 'telegram-bot-ruby'
Telegram returns me {"ok"=>true, "result"=>true} 甚至显示按钮 "switch to PM" ,但没有出现作为答案的结果。从我的角度来看,这里唯一可以打破的是我准备数组以发送结果的方式。谁能帮帮我?
这是代码示例:
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
只需将 gem 更新到版本“0.5”,它应该可以正常工作 gem install 'telegram-bot-ruby'