Easily integrate Telegrams login widget into your Laravel application to send Telegram messages
pschocke/laravel-telegram-login-widget is a Laravel package for easily integrate telegrams login widget into your laravel application to send telegram messages.
It currently has 16 GitHub stars and 10.706 downloads on Packagist (latest version v2.1.0).
Install it with composer require pschocke/laravel-telegram-login-widget.
Discover more Laravel packages by pschocke
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Telegram Login Widget. Easily integrate Telegrams login widget to send Telegram messages.
You can view a full video of the installation process an usage here, where we build an app that sends Telegram notifications from start to finish.
Via Composer
composer require pschocke/laravel-telegram-login-widget
Then publish the configuration file
php artisan vendor:publish --tag=telegramloginwidget.config
First you have to create a bot at Telegram. After that set up your login widget in your frontend.
Create an env variable TELEGRAM_BOT_TOKEN with your bots token
Create a route to handle the callback/redirect after the the successful connection between the user account and your telegram bot. Telegram uses a hash to allow you to verify the response is from Telegram. Here comes this package in play:
use pschocke\TelegramLoginWidget\Facades\TelegramLoginWidget;
class TelegramCallbackController extends Controller {
public function __invoke(Request $request) {
if($telegramUser = TelegramLoginWidget::validate($request)) {
// user is valid
}
// telegram response is not valid. Account connection failed
}
}
if you want more control over the response, you can use the validateWithError() method to catch more fine tuned errors:
use pschocke\TelegramLoginWidget\Facades\TelegramLoginWidget;
class TelegramCallbackController extends Controller {
public function __invoke(Request $request) {
$telegramUser = [];
try {
$telegramUser = TelegramLoginWidget::validateWithError($request);
} catch(pschocke\TelegramLoginWidget\Exceptions\HashValidationException $e) {
// the response is not from telegram
} catch(pschocke\TelegramLoginWidget\Exceptions\ResponseOutdatedException $e) {
// the response is outdated.
}
}
}
At this stage, $telegramUser contains a collection of all attributes Telegram provides: id, first_name, last_name, username, photo_url and auth_date.
echo $telegramUser->first_name; // Max
echo $telegramUser->last_name; // Mustermann
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email author email instead of using the issue tracker.
MIT. Please see the license file for more information.