├── README.md
├── composer.json
└── src
└── TelegramLog.php
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | ## Logging your application problems(achievements) to Telegram
10 | ### Ultralight package
11 |
12 | ## Usage
13 | ```
14 | \Log::telegram('Hey, i am your application, and i have a problem');
15 | ```
16 | .png)
17 |
18 | # Instalation
19 | ```
20 | composer require matviib/telegram-logger
21 | ```
22 | Add to your .env file:
23 | ```
24 | TELEGRAM_LOGGER_TOKEN=
25 | TELEGRAM_LOGGER_CHAT_ID=XXX,YYY
26 | #developer1 - XXX
27 | #developer2 - YYY
28 | ```
29 |
30 | # Bonus
31 | ### Creating telegram bot tutorial
32 | 1. Find BotFather.
33 | 2. Send `/newbot`.
34 | 3. Set up name and bot-name for your bot.
35 | 4. Get token and add it to your .env file.
36 | 5. Find your bot (BotFather already generate link to it in last message).
37 | 6. Send one or few messages to him.
38 | 7. Open next url `https://api.telegram.org/bot/getUpdates` and find `chat_id`.
39 |
40 | Steps #6,#7 needed for adding EACH developer to listeners of the bot.
41 |
42 | .png)
43 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "matviib/telegram-logger",
3 | "description": "Put log messages from your Laravel app to your Telegram bot",
4 | "keywords": [
5 | "laravel",
6 | "laravel-5-package",
7 | "logging",
8 | "logger",
9 | "logs",
10 | "telegram",
11 | "telegram-bot",
12 | "telegram-logger",
13 | "telegram-loging"
14 | ],
15 | "type": "library",
16 | "version": "v1.0.1",
17 | "license": "MIT",
18 | "authors": [
19 | {
20 | "name": "Matvii Bondar",
21 | "email": "matvii.bondar@gmail.com"
22 | }
23 | ],
24 | "autoload": {
25 | "psr-4": {
26 | "MatviiB\\": "src/"
27 | }
28 | },
29 | "extra": {
30 | "laravel": {
31 | "aliases": {
32 | "Log": "MatviiB\\TelegramLog"
33 | }
34 | }
35 | },
36 | "minimum-stability": "dev",
37 | "require": {
38 | "laravel/framework": "^5.0"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/TelegramLog.php:
--------------------------------------------------------------------------------
1 | ' . env('APP_NAME') . '' . PHP_EOL
20 | . '' . env('APP_ENV') . '' . PHP_EOL
21 | . 'Message:' . PHP_EOL
22 | . '' . $note . '
';
23 |
24 | try {
25 | $ids = explode(',', $chat_id);
26 |
27 | foreach ($ids as $id) {
28 | file_get_contents(
29 | 'https://api.telegram.org/bot' . $token . '/sendMessage?'
30 | . http_build_query([
31 | 'text' => $message,
32 | 'chat_id' => $id,
33 | 'parse_mode' => 'html'
34 | ])
35 | );
36 | }
37 | } catch (\Exception $e) {
38 | Log::error('TelegramLog bad token/chat_id.');
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------