-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_bicing_gram.rb
42 lines (36 loc) · 1.69 KB
/
bot_bicing_gram.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'telegram/bot'
require_relative 'data/station_information'
require_relative 'helpers/bot_helper'
require_relative 'helpers/bot_message'
TELEGRAM_BOT_TOKEN = ENV['TELEGRAM_BOT_TOKEN']
SIZE_OF_CLOSEST_STATIONS = ENV['N_OF_STATIONS']
Telegram::Bot::Client.run(TELEGRAM_BOT_TOKEN) do |bot|
bot.listen do |message|
case message
when Telegram::Bot::Types::CallbackQuery
station = BotHelper.get_stations(message.data, SIZE_OF_CLOSEST_STATIONS.to_i)
BotMessage.send_station_message(bot, message.from.id, station.reverse!.pop)
when Telegram::Bot::Types::InlineQuery
station = BotHelper.get_stations_inline(message, SIZE_OF_CLOSEST_STATIONS.to_i)
BotMessage.send_station_message(bot, message.id, station, true)
when Telegram::Bot::Types::Message
if message.venue && message.venue.location
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.inline_markup, BotMessage::BOT_ACTION_MESSAGE)
elsif message.location
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.inline_markup(message.location), BotMessage::BOT_ACTION_MESSAGE)
end
case message.text
when 'Help'
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.inline_markup, BotMessage::BOT_HELP_MESSAGE)
when 'Start'
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.inline_markup)
when '/start'
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.inline_markup)
else
unless (message.text.nil? || message.text.downcase.start_with?('in'))
BotMessage.send_bot_message(bot, message.chat.id, BotHelper.bot_markup, BotMessage::BOT_ERROR_MESSAGE)
end
end
end
end
end