Answer the question
In order to leave comments, you need to log in
Inline keyboards Ruby telegram Bot not working, How to do it right?
Greetings to all, I'm making Inline keyboards buttons for the bot, but they don't
work
anyway .
and where to replace to make the code work, thank you in advance!
require 'telegram/bot'
token = ''
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when Telegram::Bot::Types::CallbackQuery
if message.data == 'touch'
bot.api.send_message(chat_id: message.from.id, text: "Don't touch me!")
end
if message.data == 'test'
bot.api.send_message(chat_id: message.from.id, text: "Don't touch me!")
end
when '/start'
kb = [
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Test', callback_data: 'test1'),
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Touch me', callback_data: 'touch'),
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Switch to inline', switch_inline_query: 'some text')
]
markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: kb)
bot.api.send_message(chat_id: message.chat.id, text: 'Make a choice', reply_markup: markup)
end
end
end
Answer the question
In order to leave comments, you need to log in
The problem is that your case accepts message.text because of this, it will give an error when the button is clicked. Solution example:
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message
when Telegram::Bot::Types::CallbackQuery
case message.data
when 'touch'
bot.api.send_message(chat_id: message.from.id, text: "Don't touch me!")
when 'test'
bot.api.send_message(chat_id: message.from.id, text: "Don't test me!")
end
when Telegram::Bot::Types::Message
case message.text
when '/start'
kb = [
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Test', callback_data: 'test'),
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Touch me', callback_data: 'touch'),
Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Switch to inline', switch_inline_query: 'some text')
]
markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: kb)
bot.api.send_message(chat_id: message.chat.id, text: 'Make a choice', reply_markup: markup)
end
end
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question