承接 it-healer/laravel-telegram-bot 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

it-healer/laravel-telegram-bot

最新稳定版本:v1.0.4

Composer 安装命令:

composer require it-healer/laravel-telegram-bot

包简介

A library for convenient creation of Telegram bots by analogy with the creation of Web sites on Laravel.

README 文档

README

Latest Version on Packagist Total Downloads

This package for Laravel 11+ allows you to easily create interactive Telegram bots, using Laravel routing, and using Blade templates to conduct a dialogue with the user.

Installation

You can install the package via composer:

composer require it-healer/laravel-telegram-bot
php artisan telegram:install

You can publish and run the migrations with:

php artisan vendor:publish --tag="telegram-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="telegram-config"

Optionally, you can publish the views using:

php artisan vendor:publish --tag="telegram-views"

Optionally, if you use Sail for local development, you need add PHP params PHP_CLI_SERVER_WORKERS="10" in file supervisord.conf:

[program:php]
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
user=%(ENV_SUPERVISOR_PHP_USER)s
environment=LARAVEL_SAIL="1",PHP_CLI_SERVER_WORKERS="10"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

You can use Laravel Auth, edit file config/auth.php and edit section guards:

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

After this you can use middleware auth:telegram in your routes.

If you want work with automatic truncate dialogs, you must run command php artisan telegram:truncate every minute using Schedule.

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

After you can use middleware in routes:

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

Arguments - is frequency in seconds, how often to update the page.

In file routes/console.php add:

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

Usage

Create new Telegram Bot:

php artisan telegram:new-bot

Set Webhook for bot:

php artisan telegram:set-webhook

Unset Webhook for bot:

php artisan telegram:unset-webhook

Manual pooling (on localhost) for bot:

php artisan telegram:pooling [BOT_ID]

Inline Keyboard

If you want create button for change current URI query params, use this template:

<inline-keyboard>
    <row>
        <column query-param="value">Change query param</column>
    </row>
</inline-keyboard>

If you want send POST data you must use this template:

<inline-keyboard>
    <row>
        <column data-field="value">Send field value</column>
    </row>
</inline-keyboard>

If you POST data is long, you can encrypt using this template:

<inline-keyboard>
    <row>
        <column data-field="long value" encode="true">Encoded send data</column>
    </row>
</inline-keyboard>

If you want make redirect to another page from button, use this template:

<inline-keyboard>
    <row>
        <column data-redirect="/">Redirect to /</column>
    </row>
</inline-keyboard>

Edit Form

class MyForm extends \ItHealer\Telegram\EditForm\BaseForm 
{
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'min:5', 'max:255'],
            'phone' => ['required', 'string', 'min:10', 'max:15'],
        ];
    }
    
    public function titles(): array
    {
        return [
            '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'));
    }
}
<message>
    <x-telegram-edit-form :form="$form">
        <x-slot:name>
            <line>Please, enter your First Name:</line>
        </x-slot:name>
    </x-telegram-edit-form>
</message>

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 125
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-23