lib/boppers/notifier/telegram.rb in boppers-0.0.8 vs lib/boppers/notifier/telegram.rb in boppers-0.0.9
- old
+ new
@@ -4,31 +4,28 @@
module Notifier
class Telegram
attr_reader :api_token, :channel_id, :subscribe
def initialize(api_token:, channel_id:, subscribe: nil)
- require "telegram_bot"
-
@api_token = api_token
@channel_id = channel_id
@subscribe = subscribe
end
def call(title, message, options)
+ context = self
telegram_options = options.fetch(:telegram, {})
title = telegram_options.delete(:title) { title }
message = telegram_options.delete(:message) { message }
- bot = TelegramBot.new(token: api_token)
- notification = TelegramBot::OutMessage.new
- notification.chat = TelegramBot::Channel.new(id: channel_id)
- notification.text = "#{title}\n\n#{message}"
+ telegram_options[:text] = "#{title}\n\n#{message}"
+ telegram_options[:chat_id] = channel_id
- telegram_options.each do |key, value|
- notification.public_send("#{key}=", value)
+ HttpClient.post do
+ url "https://api.telegram.org/bot#{context.api_token}/sendMessage"
+ params telegram_options
+ options expect: 200
end
-
- notification.send_with(bot)
end
end
end
end