我需要從用戶的消息中獲取一個整數,並將其置於變量日。 我該怎麼做?Ruby Telegram bot - 如何從用戶消息中獲取文本並將其放入變量?
這裏的一些代碼:
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when '/start'
bot.api.sendMessage(chat_id: message.chat.id, text: "Привет, #{message.from.first_name}. Чтобы узнать сегодняшнее расписание, напишите /today")
when '/today'
bot.api.sendMessage(chat_id: message.chat.id, text: "#{date}")
if discipline1_name.size == 0 && discipline2_name.size == 0 && discipline3_name.size == 0 && discipline4_name.size == 0 && discipline5_name.size == 0 && discipline6_name.size == 0 then
(bot.api.sendMessage(chat_id: message.chat.id, text: "Сегодня воскресенье, можете отдыхать :)")
bot.api.sendMessage(chat_id: message.chat.id, text: "Чтобы узнать расписание на другой день, введите дату в формате /13 (13 - день)."))
else
unless discipline1_name.size == 0
bot.api.sendMessage(chat_id: message.chat.id, text: "1. #{discipline1_name} в кабинете #{discipline1_cab}")
else
bot.api.sendMessage(chat_id: message.chat.id, text: "1. ===========")
end
,喜歡它下降了discipline2,3,... 6
我需要的是這樣的:
when '#{message}'
day = message.to_i
page = Nokogiri::HTML(open("http://rating.ivpek.ru/timetable/timetable/show?gid=222&date=2017-10-#{day}"))
但它不起作用
你能補充你的問題嗎?你使用哪個庫?你使用webhooks還是輪詢? –
我正在使用telegram-bot-ruby-0.8.4 lib,我不使用webhooks和polling – rafulin
到目前爲止你有什麼?你如何檢索信息?信息如何顯示?您是否閱讀過文檔?你能展示一些代碼嗎? – Stefan