Class: Telegram::Bot::Botan

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/bot/botan.rb

Constant Summary collapse

API_URL =
'https://api.botan.io'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ Botan

Returns a new instance of Botan.



5
6
7
# File 'lib/telegram/bot/botan.rb', line 5

def initialize(token = nil)
  @token = token || Telegram::Bot.configuration.botan_token
end

Instance Method Details

#track(uid, message, name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/telegram/bot/botan.rb', line 9

def track(uid, message, name)
  begin
    response = Faraday.new(url: API_URL).post do |req|
      req.url "/track?token=#{@token}&uid=#{uid}&name=#{name}"
      req.headers['Content-Type'] = 'application/json'
      req.body = JSON.dump({text: message})
    end

    JSON.parse(response.body)
  rescue => e
    raise Telegram::Bot::BotanError.new(e.message)
  end
end