telegram-bot-ruby
telegram-bot-ruby copied to clipboard
How to save user's text messages correctly?
I want to make quiz. But I don't understand how to do it.
I can't save user's message correctly.
For example I have one question:
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
bot.api.send_message(chat_id: message.chat.id, text: '2+2')
bot.api.send_message(chat_id: message.chat.id, text: 'OK') if message.text == '4'
end
end
So dialogue is:
/start
2+2
4
2+2
OK
Using filter /start
:
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when '/start'
bot.api.send_message(chat_id: message.chat.id, text: '2+2')
bot.api.send_message(chat_id: message.chat.id, text: 'OK') if message.text == '4'
end
end
end
So dialogue:
/start
2+2
4
If we have only one question we can do something like this:
bot.listen do |message|
case message.text
when '/start'
bot.api.send_message(chat_id: message.chat.id, text: '2+2')
when message.text == '4'
bot.api.send_message(chat_id: message.chat.id, text: 'OK')
end
end
end
But for full quiz functionality, I think you need to add a database to your application and store last user action for understanding on which step the user is now.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.