Class: Boppers::Notifier::Telegram
- Inherits:
-
Object
- Object
- Boppers::Notifier::Telegram
- Defined in:
- lib/boppers/notifier/telegram.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#subscribe ⇒ Object
readonly
Returns the value of attribute subscribe.
Instance Method Summary collapse
- #call(title, message, options) ⇒ Object
-
#initialize(api_token:, channel_id:, subscribe: nil) ⇒ Telegram
constructor
A new instance of Telegram.
Constructor Details
#initialize(api_token:, channel_id:, subscribe: nil) ⇒ Telegram
Returns a new instance of Telegram.
8 9 10 11 12 |
# File 'lib/boppers/notifier/telegram.rb', line 8 def initialize(api_token:, channel_id:, subscribe: nil) @api_token = api_token @channel_id = channel_id @subscribe = subscribe end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
6 7 8 |
# File 'lib/boppers/notifier/telegram.rb', line 6 def api_token @api_token end |
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
6 7 8 |
# File 'lib/boppers/notifier/telegram.rb', line 6 def channel_id @channel_id end |
#subscribe ⇒ Object (readonly)
Returns the value of attribute subscribe.
6 7 8 |
# File 'lib/boppers/notifier/telegram.rb', line 6 def subscribe @subscribe end |
Instance Method Details
#call(title, message, options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/boppers/notifier/telegram.rb', line 14 def call(title, , ) context = self = .fetch(:telegram, {}) title = .delete(:title) { title } = .delete(:message) { } [:text] = "#{title}\n\n#{message}" [:chat_id] = channel_id HttpClient.post do url "https://api.telegram.org/bot#{context.api_token}/sendMessage" params expect: 200 end end |