PHPackages                             al3x5/xbot-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. al3x5/xbot-laravel

ActiveLibrary[Framework](/categories/framework)

al3x5/xbot-laravel
==================

Laravel integration for xBot library

v0.2.4(1mo ago)035MITPHPPHP &gt;=8.2

Since Dec 11Pushed 1mo agoCompare

[ Source](https://github.com/al3x5dev/xbot-laravel)[ Packagist](https://packagist.org/packages/al3x5/xbot-laravel)[ RSS](/packages/al3x5-xbot-laravel/feed)WikiDiscussions main Synced today

READMEChangelog (7)Dependencies (12)Versions (9)Used By (0)

xBot Laravel
============

[](#xbot-laravel)

Seamless integration of [xBot](https://github.com/al3x5dev/xbot/) the powerful PHP library for creating Telegram bots with the [Laravel framework](https://github.com/laravel/laravel).

🚀 Features
----------

[](#-features)

- **Artisan Commands**: Use xBot through familiar Laravel commands
- **Laravel Cache Integration**: Automatic PSR-16 adapter
- **Laravel Configuration**: Native Laravel configuration system
- **Dependency Injection**: Type-hint Bot in controllers for automatic injection
- **Service Container**: Bot registered as singleton in Laravel container
- **Webhook Management**: Easy webhook configuration for Telegram bots

📦 Installation
--------------

[](#-installation)

```
composer require al3x5/xbot-laravel
```

⚡ Quick Start
-------------

[](#-quick-start)

### 1. Install and Configure

[](#1-install-and-configure)

```
php artisan xbot
```

This command will:

- Configure the Laravel API (Sanctum)
- Publish the xBot configuration
- Create bot directory structure (commands, callbacks, middlewares)
- Create default command classes (Start, Help)
- Generate middleware configuration

### 2. Configure your Bot

[](#2-configure-your-bot)

Add to your `.env` file:

```
BOT_TOKEN=1234567890:ABCDEFGHIJKLMNOQRSTZ
```

### 3. Register default commands and callback functions

[](#3-register-default-commands-and-callback-functions)

```
php artisan xbot:register
```

### 4. Configure Webhook

[](#4-configure-webhook)

```
php artisan xbot:hook:set https://yourdomain.com/xbot/api/webhook
```

### 5. Create Your Commands

[](#5-create-your-commands)

```
php artisan xbot:telegram:command HelloWorld
```

🛠 Available Commands
--------------------

[](#-available-commands)

CommandDescription`php artisan xbot`Install and configure xBot`php artisan xbot:register`Register all commands and callbacks`php artisan xbot:hook:set `Set webhook URL`php artisan xbot:hook:delete`Delete webhook`php artisan xbot:hook:info`Get webhook info`php artisan xbot:hook:about`Get bot info`php artisan xbot:telegram:command `Create new command`php artisan xbot:telegram:callback  `Create new callback handler`php artisan xbot:telegram:conversation `Create new conversation`php artisan xbot:telegram:handler `Create new handler`php artisan xbot:telegram:middleware `Create new middleware⚙️ Settings
-----------

[](#️-settings)

After installation, add to your `.env`:

```
BOT_TOKEN=1234567890:ABCDEFGHIJKLMNOQRSTZ
BOT_SECRET=your_secret_key (optional)
BOT_MANAGERS=123456789,985632147 (optional)
BOT_WEBHOOK_URL=https://yourdomain.com/bot (optional)
```

**Parameter descriptions:**

- **BOT\_TOKEN** — Your Telegram bot token (issued by @BotFather). **Required.**
- **BOT\_SECRET** — Secret token to verify webhook authenticity (`X-Telegram-Bot-Api-Secret-Token` header). Optional but recommended.
- **BOT\_MANAGERS** — Telegram user IDs of bot administrators, comma-separated. Enables the `isAdmin()` method to restrict commands. Optional.
- **BOT\_WEBHOOK\_URL** — Public URL where Telegram will send updates. Only needed if using webhook instead of polling. Optional.

🌐 Webhook Route
---------------

[](#-webhook-route)

Add to your `routes/api.php`:

```
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/bot', function (Request $request) {
    app('xbot')->run();
});
```

🔧 Dependency Injection
----------------------

[](#-dependency-injection)

### Type-hinting in Controllers

[](#type-hinting-in-controllers)

The Bot is registered as a singleton in Laravel's service container. You can inject it directly:

```
