ermanojbisht/mkb-laravel-telegram-login-widget
Composer 安装命令:
composer require ermanojbisht/mkb-laravel-telegram-login-widget
包简介
Easily integrate Telegrams login widget into your Laravel application to send Telegram messages
README 文档
README
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.
Installation
Via Composer
composer require pschocke/laravel-telegram-login-widget
Then publish the configuration file
php artisan vendor:publish --tag=telegramloginwidget.config
Usage
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
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-26