Skip to content

Commit c13bf3a

Browse files
committed
initial
0 parents  commit c13bf3a

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

src/TelegramLog.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

0 commit comments

Comments
 (0)