tg_error_notifier 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/tg_error_notifier/notifier.rb +31 -0
- data/lib/tg_error_notifier/version.rb +1 -1
- data/lib/tg_error_notifier.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 990692433d408163d933c9efad9d4ddfc2db0993635f61070acc0d5435df309b
|
|
4
|
+
data.tar.gz: 45d8c5f03c584670bc215eb0b683f460787069a8cde044375aa4120d33ba19d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73993633c8eb9a88aeccb9d53b70c423f9dafd85eb36a72fcece8b31e5b3ce968b81d41303c10355da9c5a6997c298126fe105c65a39e721546b487629c13f33
|
|
7
|
+
data.tar.gz: 450edb567628c5559b69eacc55c504fbced183b643312583937075a39d99298bd64a10f64c534e8470b5057e02c8b0c8486c1d62bbf1f0a51aa319aaaaed3e1c
|
data/README.md
CHANGED
|
@@ -90,3 +90,15 @@ end
|
|
|
90
90
|
- `{ sent: true, status: :sent, code: 200 }`
|
|
91
91
|
- `{ sent: false, status: :skipped, reason: "missing_chat_id" }`
|
|
92
92
|
- `{ sent: false, status: :failed, reason: "telegram_api_error", code: 400, body: "..." }`
|
|
93
|
+
|
|
94
|
+
## Manual message
|
|
95
|
+
```ruby
|
|
96
|
+
TgErrorNotifier.capture_message(
|
|
97
|
+
"Background sync started",
|
|
98
|
+
level: :info,
|
|
99
|
+
source: "custom",
|
|
100
|
+
context: { feature: "sync", user_id: current_user&.id }
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`capture_message` returns the same diagnostic hash format as `capture_exception`.
|
|
@@ -30,6 +30,20 @@ module TgErrorNotifier
|
|
|
30
30
|
{ sent: false, status: :failed, reason: e.class.name, error: e.message }
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def notify_message(message:, level:, source:, context: {})
|
|
34
|
+
enabled_check = enabled_status
|
|
35
|
+
unless enabled_check[:enabled]
|
|
36
|
+
log("skipped: #{enabled_check[:reason]}")
|
|
37
|
+
return { sent: false, status: :skipped, reason: enabled_check[:reason] }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
payload = build_message_payload(message: message, level: level, source: source, context: context)
|
|
41
|
+
send_payload(payload)
|
|
42
|
+
rescue StandardError => e
|
|
43
|
+
log("notify_message failed: #{e.class}: #{e.message}")
|
|
44
|
+
{ sent: false, status: :failed, reason: e.class.name, error: e.message }
|
|
45
|
+
end
|
|
46
|
+
|
|
33
47
|
private
|
|
34
48
|
|
|
35
49
|
attr_reader :config
|
|
@@ -105,6 +119,23 @@ module TgErrorNotifier
|
|
|
105
119
|
formatted.join("\n")
|
|
106
120
|
end
|
|
107
121
|
|
|
122
|
+
def build_message_payload(message:, level:, source:, context: {})
|
|
123
|
+
text = [
|
|
124
|
+
"<b>ℹ️ #{escape(resolve(config.app_name).to_s)}: #{escape(resolve(config.environment).to_s)}</b>",
|
|
125
|
+
"<b>Source:</b> #{escape(source.to_s)}",
|
|
126
|
+
"<b>Level:</b> <code>#{escape(level.to_s)}</code>",
|
|
127
|
+
"<b>Message:</b> #{escape(message.to_s)}",
|
|
128
|
+
context_block(context)
|
|
129
|
+
].compact.join("\n")
|
|
130
|
+
|
|
131
|
+
{
|
|
132
|
+
chat_id: resolve(config.chat_id),
|
|
133
|
+
text: truncate(text),
|
|
134
|
+
parse_mode: "HTML",
|
|
135
|
+
disable_web_page_preview: true
|
|
136
|
+
}
|
|
137
|
+
end
|
|
138
|
+
|
|
108
139
|
def truncate(text)
|
|
109
140
|
return text if text.length <= MAX_MESSAGE_LENGTH
|
|
110
141
|
|
data/lib/tg_error_notifier.rb
CHANGED
|
@@ -27,6 +27,11 @@ module TgErrorNotifier
|
|
|
27
27
|
notify(exception: exception, source: source, context: context)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# API similar to Sentry.capture_message("text")
|
|
31
|
+
def capture_message(message, level: :info, source: "manual", context: {})
|
|
32
|
+
notifier.notify_message(message: message, level: level, source: source, context: context)
|
|
33
|
+
end
|
|
34
|
+
|
|
30
35
|
private
|
|
31
36
|
|
|
32
37
|
def notifier
|