Sha256: b6bf6969bdc6d8fcf0a8f64961d02e106db95c799f92617c0144dba0835813b4

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

module Boppers
  module Notifier
    class Telegram
      attr_reader :api_token, :channel_id, :subscribe

      def initialize(api_token:, channel_id:, subscribe: nil)
        @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 }

        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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
boppers-0.0.11 lib/boppers/notifier/telegram.rb
boppers-0.0.10 lib/boppers/notifier/telegram.rb
boppers-0.0.9 lib/boppers/notifier/telegram.rb