Class: SpreeCmCommissioner::TelegramNotifier
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::TelegramNotifier
- Defined in:
- app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb
Instance Attribute Summary collapse
-
#base_options ⇒ Object
readonly
Returns the value of attribute base_options.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#telegram_client ⇒ Object
readonly
Returns the value of attribute telegram_client.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #backtrace_message(exception) ⇒ Object
- #body(exception, formatter, data, telegram_exception) ⇒ Object
- #call(exception, opts = {}) ⇒ Object
-
#initialize(options) ⇒ TelegramNotifier
constructor
A new instance of TelegramNotifier.
Constructor Details
#initialize(options) ⇒ TelegramNotifier
Returns a new instance of TelegramNotifier.
5 6 7 8 9 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 5 def initialize() @base_options = @channel_id = .delete(:channel_id) @telegram_client = ::Telegram.bots[:exception_notifier] end |
Instance Attribute Details
#base_options ⇒ Object (readonly)
Returns the value of attribute base_options.
3 4 5 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 3 def @base_options end |
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
3 4 5 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 3 def channel_id @channel_id end |
#telegram_client ⇒ Object (readonly)
Returns the value of attribute telegram_client.
3 4 5 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 3 def telegram_client @telegram_client end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 3 def token @token end |
Instance Method Details
#backtrace_message(exception) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 68 def (exception) backtrace = exception.backtrace return if backtrace.blank? text = [] text << '```' backtrace.first(5).each { |line| text << "* #{line}" } text << '```' text.join("\n") end |
#body(exception, formatter, data, telegram_exception) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 30 def body(exception, formatter, data, telegram_exception) text = [] text << "<b>Application #{formatter.app_name}</b>" text << "\n" text << formatter.title text << formatter.subtitle text << "\n" text << '<b>Exception:</b>' text << exception. text << "\n" if data.present? text << '<b>Set by controller:</b>' text << "<code>#{data}</code>" text << "\n" end if formatter..present? && formatter. != "```\n```" text << '<b>Request:</b>' text << "<code>#{formatter.}</code>" text << "\n" end backtrace = (exception) if backtrace.present? text << '<b>Backtrace:</b>' text << "<code>#{backtrace}</code>" text << "\n" end text << telegram_exception.to_s if telegram_exception.present? text.compact.join("\n") end |
#call(exception, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/exception_notifier/spree_cm_commissioner/telegram_notifier.rb', line 11 def call(exception, opts = {}) = .merge(opts) formatter = ::ExceptionNotifier::Formatter.new(exception, ) data = [:env]['exception_notifier.exception_data'] telegram_client.( chat_id: channel_id, parse_mode: 'HTML', text: body(exception, formatter, data, nil) ) rescue ::Telegram::Bot::Error => e # when telegram bot error, we try to send again without parse (raw text), # so we still can get exceptions and know what cause telegram error. telegram_client.( chat_id: channel_id, text: body(exception, formatter, data, e) ) end |