我需要从用户的消息中获取一个整数,并将其置于变量日。 我该怎么做?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