Giter Site home page Giter Site logo

ermanojbisht / mkb-laravel-telegram-login-widget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pschocke/laravel-telegram-login-widget

0.0 0.0 0.0 55 KB

Easily integrate Telegram login and verify the response

Home Page: https://patrickschocke.de/sending-telegram-messages-with-laravel-notifications

License: MIT License

PHP 100.00%

mkb-laravel-telegram-login-widget's Introduction

TelegramLoginWidget

Latest Version on Packagist Total Downloads run-tests Quality Score StyleCI codecov

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.

mkb-laravel-telegram-login-widget's People

Contributors

pschocke avatar ermanojbisht avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.