-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.rb
More file actions
28 lines (22 loc) · 732 Bytes
/
Copy pathbot.rb
File metadata and controls
28 lines (22 loc) · 732 Bytes
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
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require 'telegram/bot'
BOT_KEY = ENV.delete('TELEGRAMBOTSECRETKEY')
BOT = Telegram::Bot::Client.new(BOT_KEY)
Signal.trap('INT') do
BOT.stop
end
BOT.listen do |message|
# it will be in an infinity loop until `bot.stop` command
# (with a small delay for the current `fetch_updates` request)
case message.text
when '/start'
BOT.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
when '/stop'
BOT.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}")
else # echo
BOT.api.send_message(chat_id: message.chat.id, text: message.text)
end
end