mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 13:23:04 +01:00
Added telegram notifications
This commit is contained in:
@@ -24,4 +24,7 @@ REMEMBER_DAYS=30
|
||||
|
||||
SLACK_WEBHOOK=
|
||||
|
||||
TELEGRAM_BOT_TOKEN=
|
||||
TELEGRAM_CHAT_ID=
|
||||
|
||||
BASE_PATH=
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Speedtest Tracker
|
||||
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
|
||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [speedtest-cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||
|
||||
@@ -11,7 +11,7 @@ This program runs a speedtest check every hour and graphs the results. The back-
|
||||
- Automatically run a speedtest every hour
|
||||
- Graph of previous speedtests going back x days
|
||||
- Backup/restore data in JSON/CSV format
|
||||
- Slack/Discord notifications
|
||||
- Slack/Discord/Telegram notifications
|
||||
- Organizr integration
|
||||
|
||||
## Installation & Setup
|
||||
@@ -28,6 +28,7 @@ docker create \
|
||||
-e SLACK_WEBHOOK=webhook `#optional` \
|
||||
-e PUID=uid `#optional` \
|
||||
-e PGID=gid `#optional` \
|
||||
-e OOKLA_EULA_GDPR=true \
|
||||
--restart unless-stopped \
|
||||
henrywhitaker3/speedtest-tracker
|
||||
```
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Notifications\SpeedtestComplete;
|
||||
use App\Notifications\SpeedtestCompleteSlack;
|
||||
use App\Notifications\SpeedtestCompleteTelegram;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
|
||||
class SpeedtestCompleteListener
|
||||
{
|
||||
@@ -29,15 +31,25 @@ class SpeedtestCompleteListener
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
$data = $event->speedtest;
|
||||
if(env('SLACK_WEBHOOK')) {
|
||||
$data = $event->speedtest;
|
||||
try {
|
||||
Notification::route('slack', env('SLACK_WEBHOOK'))
|
||||
->notify(new SpeedtestComplete($data));
|
||||
->notify(new SpeedtestCompleteSlack($data));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your sleck webhook is invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
|
||||
if(env('TELEGRAM_BOT_TOKEN') && env('TELEGRAM_CHAT_ID')) {
|
||||
try {
|
||||
Notification::route(TelegramChannel::class, env('TELEGRAM_CHAT_ID'))
|
||||
->notify(new SpeedtestCompleteTelegram($data));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your telegram settings are invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,11 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
use NotificationChannels\Telegram\TelegramMessage;
|
||||
|
||||
class SpeedtestComplete extends Notification
|
||||
class SpeedtestCompleteSlack extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
@@ -20,6 +23,9 @@ class SpeedtestComplete extends Notification
|
||||
*/
|
||||
public function __construct($speedtest)
|
||||
{
|
||||
$speedtest->ping = number_format((float)$speedtest->ping, 1, '.', '');
|
||||
$speedtest->download = number_format((float)$speedtest->download, 1, '.', '');
|
||||
$speedtest->upload = number_format((float)$speedtest->upload, 1, '.', '');
|
||||
$this->speedtest = $speedtest;
|
||||
}
|
||||
|
||||
@@ -31,7 +37,9 @@ class SpeedtestComplete extends Notification
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['slack'];
|
||||
return [
|
||||
'slack',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,9 +56,9 @@ class SpeedtestComplete extends Notification
|
||||
->attachment(function ($attachment) use ($speedtest) {
|
||||
$attachment->title('New speedtest')
|
||||
->fields([
|
||||
'Ping' => number_format((float)$speedtest->ping, 1, '.', '') . ' ms',
|
||||
'Download' => number_format((float)$speedtest->download, 1, '.', '') . ' Mbit/s',
|
||||
'Upload' => number_format((float)$speedtest->upload, 1, '.', '') . ' Mbit/s',
|
||||
'Ping' => $speedtest->ping . ' ms',
|
||||
'Download' => $speedtest->download . ' Mbit/s',
|
||||
'Upload' => $speedtest->upload . ' Mbit/s',
|
||||
]);
|
||||
});
|
||||
}
|
||||
73
app/Notifications/SpeedtestCompleteTelegram.php
Normal file
73
app/Notifications/SpeedtestCompleteTelegram.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
use NotificationChannels\Telegram\TelegramMessage;
|
||||
|
||||
class SpeedtestCompleteTelegram extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($speedtest)
|
||||
{
|
||||
$speedtest->ping = number_format((float)$speedtest->ping, 1, '.', '');
|
||||
$speedtest->download = number_format((float)$speedtest->download, 1, '.', '');
|
||||
$speedtest->upload = number_format((float)$speedtest->upload, 1, '.', '');
|
||||
$this->speedtest = $speedtest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [
|
||||
TelegramChannel::class
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format tekegram notification
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return TelegramMessage
|
||||
*/
|
||||
public function toTelegram($notifiable)
|
||||
{
|
||||
$speedtest = $this->speedtest;
|
||||
$msg = "*New Speedtest*
|
||||
Ping: *$speedtest->ping*
|
||||
Download: *$speedtest->download*
|
||||
Upload: *$speedtest->upload*";
|
||||
return TelegramMessage::create()
|
||||
->to(env('TELEGRAM_CHAT_ID'))
|
||||
->content($msg)
|
||||
->options(['parse_mode' => 'Markdown']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
{
|
||||
"1.6.0": [
|
||||
{
|
||||
"description": "Added telegram notifications",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.5.6": [
|
||||
{
|
||||
"description": "Auto-update all tests table",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"fideloper/proxy": "^4.2",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^6.3",
|
||||
"laravel-notification-channels/telegram": "^0.4.0",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravel/slack-notification-channel": "^2.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
|
||||
63
composer.lock
generated
63
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ea45a7c53e5c9b5a8599abd05c8ed7ad",
|
||||
"content-hash": "1f8e2d768bdcfbd5bf18db3f114479c8",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
@@ -981,6 +981,67 @@
|
||||
],
|
||||
"time": "2019-07-01T23:21:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-notification-channels/telegram",
|
||||
"version": "0.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel-notification-channels/telegram.git",
|
||||
"reference": "9e4bb2fbf1a7a06e8849fa2d50bf57fa7c4483e3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel-notification-channels/telegram/zipball/9e4bb2fbf1a7a06e8849fa2d50bf57fa7c4483e3",
|
||||
"reference": "9e4bb2fbf1a7a06e8849fa2d50bf57fa7c4483e3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^6.2",
|
||||
"illuminate/notifications": "^5.5 || ^6.0 || ^7.0",
|
||||
"illuminate/support": "^5.5 || ^6.0 || ^7.0",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.3",
|
||||
"phpunit/phpunit": "^7.0 || ^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"NotificationChannels\\Telegram\\TelegramServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"NotificationChannels\\Telegram\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Irfaq Syed",
|
||||
"email": "syed@lukonet.com",
|
||||
"homepage": "https://lukonet.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Telegram Notifications Channel for Laravel",
|
||||
"homepage": "https://github.com/laravel-notification-channels/telegram",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"notification",
|
||||
"telegram",
|
||||
"telegram notification",
|
||||
"telegram notifications channel"
|
||||
],
|
||||
"time": "2020-06-02T06:05:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v7.16.1",
|
||||
|
||||
@@ -162,6 +162,8 @@ return [
|
||||
Illuminate\Validation\ValidationServiceProvider::class,
|
||||
Illuminate\View\ViewServiceProvider::class,
|
||||
|
||||
NotificationChannels\Telegram\TelegramServiceProvider::class,
|
||||
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
@@ -30,4 +30,8 @@ return [
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'telegram-bot-api' => [
|
||||
'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.5.6',
|
||||
'version' => '1.6.0',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user