Class: Pechkin::Connector::Telegram

Inherits:
Base
  • Object
show all
Defined in:
lib/pechkin/connector/telegram.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Base

Base::DEFAULT_HEADERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#post_data, #preview

Constructor Details

#initialize(bot_token, name) ⇒ Telegram

Returns a new instance of Telegram.



6
7
8
9
10
11
# File 'lib/pechkin/connector/telegram.rb', line 6

def initialize(bot_token, name)
  super()

  @bot_token = bot_token
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pechkin/connector/telegram.rb', line 4

def name
  @name
end

Instance Method Details

#send_message(chat_id, message, message_desc) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/pechkin/connector/telegram.rb', line 13

def send_message(chat_id, message, message_desc)
  options = { parse_mode: message_desc['telegram_parse_mode'] || 'HTML' }
  params = options.update(chat_id: chat_id, text: message)

  response = post_data(method_url('sendMessage'), params)
  { chat_id: chat_id, code: response.code.to_i, response: response.body }
end