PHP code example of mollsoft / laravel-telegram-bot

1. Go to this page and download the library: Download mollsoft/laravel-telegram-bot 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/ */

    

mollsoft / laravel-telegram-bot example snippets


'guards' => [
        'web' => [...],
        'telegram' => [
            'driver' => 'telegram',
            'provider' => 'users',
        ]
    ],

->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'telegram.live' => \Mollsoft\Telegram\Middleware\LiveMiddleware::class,
    ]);
})

Route::telegram('/', [\App\Telegram\Controllers\MyController::class, 'index'])
    ->middleware(['telegram.live:30']);

Schedule::command('telegram:live')
    ->runInBackground()
    ->everyMinute();

php artisan telegram:new-bot

php artisan telegram:set-webhook

php artisan telegram:unset-webhook

php artisan telegram:pooling [BOT_ID]

class MyForm extends \Mollsoft\Telegram\EditForm\BaseForm 
{
    public function rules(): array
    {
        return [
            'name' => ['urn [
            'name' => 'Ваше имя',
            'phone' => 'Ваш номер телефона'
        ];
    }
}

class MyController 
{
    public function edit(MyForm $form): mixed
    {
        $form->setDefault([
            'name' => 'Default name',
            'phone' => '1234567890',
        ]);
        
        if( $form->validate() ) {
            // $form->get();
        }
        
        return view('...', compact('form'));
    }
    
    public function create(MyForm $form): mixed
    {
        if( $form->isCreate()->validate() ) {
            // $form->get();
        }
        
        return view('...', compact('form'));
    }
}
bash
php artisan telegram:install
bash
php artisan vendor:publish --tag="telegram-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="telegram-config"
bash
php artisan vendor:publish --tag="telegram-views"