PHP code example of micromagicman / laravel-telegram-webapp

1. Go to this page and download the library: Download micromagicman/laravel-telegram-webapp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

micromagicman / laravel-telegram-webapp example snippets


@extends('telegram-webapp::main')

@section('lang', 'CN')

@section('head')
// some scripts, css, meta
@endsection

@section('title', 'My title')

@section('content')
    <div id="app-content">
        // My spa content
    </div>
@endsection

use Micromagicman\TelegramWebApp\Facades\TelegramWebApp;

$response = TelegramWebApp::getMe();

use Micromagicman\TelegramWebApp\Services\TelegramWebAppService;

class MyController extends Controller
{
    protected $telegram;

    public function __construct(TelegramWebAppService $telegram)
    {
        $this->telegram = $telegram;
    }

    public function getBotInfo()
    {
        $response = $this->telegram->getMe();
        return response()->json($response);
    }
}

use Micromagicman\TelegramWebApp\Dto\TelegramUser;

class MyController extends Controller
{
    public function process(Request $request, TelegramUser $user)
    {
        $id = $user->getId();
        // ...
    }
}

// config/telegram-webapp.php
'signature' => [
    'enabled' => env('TELEGRAM_WEBAPP_SIGNATURE_VALIDATION_ENABLED', false),
    'publicKey' => env('TELEGRAM_WEBAPP_SIGNATURE_PUBLIC_KEY'),
    'botId' => env('TELEGRAM_WEBAPP_SIGNATURE_BOT_ID'),
],
bash
php artisan telegram-webapp:install
bash
php artisan vendor:publish --provider="Micromagicman\TelegramWebApp\TelegramWebAppServiceProvider"