Class: Boppers::Notifier::Telegram

Inherits:
Object
  • Object
show all
Defined in:
lib/boppers/notifier/telegram.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token:, channel_id:, subscribe: nil) ⇒ Telegram

Returns a new instance of Telegram.



8
9
10
11
12
13
14
# File 'lib/boppers/notifier/telegram.rb', line 8

def initialize(api_token:, channel_id:, subscribe: nil)
  require "telegram_bot"

  @api_token = api_token
  @channel_id = channel_id
  @subscribe = subscribe
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



6
7
8
# File 'lib/boppers/notifier/telegram.rb', line 6

def api_token
  @api_token
end

#channel_idObject (readonly)

Returns the value of attribute channel_id.



6
7
8
# File 'lib/boppers/notifier/telegram.rb', line 6

def channel_id
  @channel_id
end

#subscribeObject (readonly)

Returns the value of attribute subscribe.



6
7
8
# File 'lib/boppers/notifier/telegram.rb', line 6

def subscribe
  @subscribe
end

Instance Method Details

#call(title, message, _options) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/boppers/notifier/telegram.rb', line 16

def call(title, message, _options)
  bot = TelegramBot.new(token: api_token)

  notification = TelegramBot::OutMessage.new
  notification.chat = TelegramBot::Channel.new(id: channel_id)
  notification.text = "#{title}\n\n#{message}"
  notification.send_with(bot)
end