Sha256: de0408243f81ec7d9bd2f50820e29de7c18caf1386016b41d340beaccb64f966

Contents?: true

Size: 1.05 KB

Versions: 39

Compression:

Stored size: 1.05 KB

Contents



class Telegram_2

  attr_accessor :telegram_api_url, :telegram_chat_id

  def initialize(telegram_api_url, telegram_chat_id)
    @telegram_api_url = telegram_api_url
    @telegram_chat_id = telegram_chat_id
  end

  #procedure for send log to telegram chat
  def telegram_message(message)
    begin
      uri = URI.parse(telegram_api_url)
      https_connector = Net::HTTP.new(uri.host, uri.port)
      https_connector.use_ssl = true
      data = {chat_id: telegram_chat_id, text: message}
      request_mess = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'})
      request_mess.body = data.to_json
      response_mess = https_connector.request(request_mess)
      body = response_mess.body
      return {:code => 200,
              :result => "Request completed successfully",
              :body => {:telegram_resp => JSON.parse(body.to_s),
                        :description => "Telegram message to telegram_chat_id: #{telegram_chat_id.to_s}"}}
    rescue
      return {:code => 507, :result => "Unknown SDK error"}
    end
  end


end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
imperituroard-1.1.23 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.22 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.21 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.20 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.19 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.18 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.17 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.15 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.14 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.13 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.12 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.11 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.10 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.9 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.8 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.7 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.5 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.4 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.3 lib/imperituroard/platforms/public/telegram.rb
imperituroard-1.1.2 lib/imperituroard/platforms/public/telegram.rb