class Boppers::Notifier::Telegram

Attributes

api_token[R]
channel_id[R]
subscribe[R]

Public Class Methods

new(api_token:, channel_id:, subscribe: nil) click to toggle source
# File lib/boppers/notifier/telegram.rb, line 8
def initialize(api_token:, channel_id:, subscribe: nil)
  @api_token = api_token
  @channel_id = channel_id
  @subscribe = subscribe
end

Public Instance Methods

call(title, message, options) click to toggle source
# File lib/boppers/notifier/telegram.rb, line 14
def call(title, message, options)
  context = self
  telegram_options = options.fetch(:telegram, {})
  title = telegram_options.delete(:title) { title }
  message = telegram_options.delete(:message) { message }

  telegram_options[:text] = "#{title}\n\n#{message}"
  telegram_options[:chat_id] = channel_id

  HttpClient.post do
    url "https://api.telegram.org/bot#{context.api_token}/sendMessage"
    params telegram_options
    options expect: 200
  end
end