File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " matviib/telegram-logger" ,
3
+ "description" : " " ,
4
+ "keywords" : [],
5
+ "type" : " library" ,
6
+ "version" : " v0.0.1" ,
7
+ "license" : " MIT" ,
8
+ "authors" : [
9
+ {
10
+ "name" : " Matvii Bondar" ,
11
+ "email" : " matvii.bondar@gmail.com"
12
+ }
13
+ ],
14
+ "autoload" : {
15
+ "psr-4" : {
16
+ "MatviiB\\ " : " src/"
17
+ }
18
+ },
19
+ "extra" : {
20
+ "laravel" : {
21
+ "aliases" : {
22
+ "Log" : " MatviiB\\ TelegramLog"
23
+ }
24
+ }
25
+ },
26
+ "minimum-stability" : " dev" ,
27
+ "require" : {}
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MatviiB ;
4
+
5
+ use Illuminate \Support \Facades \Log ;
6
+
7
+ class TelegramLog extends Log
8
+ {
9
+ /**
10
+ * Send note to developers with telegram
11
+ *
12
+ * @param $note
13
+ */
14
+ public static function telegram ($ note )
15
+ {
16
+ $ token = env ('TELEGRAM_LOG_TOKEN ' );
17
+ $ chat_id = env ('TELEGRAM_CHAT_ID ' );
18
+
19
+ // to get chat_id send message to bot and then open the url:
20
+ // https://api.telegram.org/bot<YourBOTToken>/getUpdates.
21
+ // search chat_id. this steps needed for adding EACH developer.
22
+
23
+ $ message = '<b> ' . env ('APP_NAME ' ) . '</b> ' . PHP_EOL
24
+ . '<b> ' . env ('APP_ENV ' ) . '</b> ' . PHP_EOL
25
+ . '<i>Message:</i> ' . PHP_EOL
26
+ . '<code> ' . $ note . '</code> ' ;
27
+
28
+ try {
29
+ $ ids = explode (', ' , $ chat_id );
30
+
31
+ foreach ($ ids as $ id ) {
32
+ file_get_contents (
33
+ 'https://api.telegram.org/bot ' . $ token . '/sendMessage? '
34
+ . http_build_query ([
35
+ 'text ' => $ message ,
36
+ 'chat_id ' => $ id ,
37
+ 'parse_mode ' => 'html '
38
+ ])
39
+ );
40
+ }
41
+ } catch (\Exception $ e ) {
42
+ Log::error ('TelegramLog bad token/chat_id. ' );
43
+ }
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments