PHPackages                             arodu/tebo - 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. arodu/tebo

ActiveCakephp-plugin

arodu/tebo
==========

TeBo plugin for CakePHP

v2.0.1(1y ago)31911MITPHPPHP &gt;=8.1

Since Mar 1Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/arodu/cakephp-tebo)[ Packagist](https://packagist.org/packages/arodu/tebo)[ RSS](/packages/arodu-tebo/feed)WikiDiscussions 2.next-cake5 Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

TeBo: CakePHP plugin for Telegram Bot
=====================================

[](#tebo-cakephp-plugin-for-telegram-bot)

[![Latest Version](https://camo.githubusercontent.com/79d3105b8cdff711600d5556fba955d756715f9b66665119e3d3c80de0a5aa7c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f61726f64752f63616b657068702d7465626f2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/arodu/cakephp-tebo/releases)[![Packagist License](https://camo.githubusercontent.com/df434648612873d01bfd94e17847e7b1db706f2b86441c465dcce39787b0e577/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61726f64752f7465626f3f7374796c653d666f722d7468652d6261646765)](LICENSE)[![GitHub Repo stars](https://camo.githubusercontent.com/d87ba984f5bcf23c5a11daaecad153dd4bad75f3950dce6e70f44265428e09ed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f61726f64752f63616b657068702d7465626f3f7374796c653d666f722d7468652d6261646765)](https://github.com/arodu/cakephp-tebo/stargazers)[![Total Downloads](https://camo.githubusercontent.com/d330cf5df8b4689027673b2f97d0ad3a4d757e5e8a9f1c1e38e18bba91bca4ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61726f64752f7465626f2e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/arodu/tebo)

TeBo is a plugin that integrates a Telegram bot into CakePHP 5 applications, allowing configuration and management of custom commands with an easy setup.

Installation
------------

[](#installation)

1. Install the plugin using Composer:

    ```
    composer require arodu/tebo
    ```
2. Load the plugin in your project:

    ```
    bin/cake plugin load TeBo
    ```
3. Add your Telegram bot token to the `.env` file, or set it as an environment variable:

    ```
    export TELEGRAM_TOKEN="xxxxx"
    ```

Webhook Configuration
---------------------

[](#webhook-configuration)

TeBo offers commands to manage the webhook setup in Telegram. To run these commands, use:

```
bin/cake tebo
```

The available options are:

1. **Get Webhook URL**: Displays the current webhook URL configured on the local system.
2. **Set Webhook to telegram**: Sets the webhook on Telegram, linking the bot to a specific URL to receive updates.
3. **Delete Webhook from telegram**: Deletes the webhook from Telegram, stopping the bot from receiving updates.
4. **Get Webhook info from telegram**: Shows information about the webhook configured on Telegram, including status and connection details.
5. **Get bot info**: Displays information about the bot, including the bot's name, username, and ID.

### Additional Configuration (Optional)

[](#additional-configuration-optional)

You can add the following values to the `.env` file to enhance webhook functionality:

```
export WEBHOOK_OBFUSCATION="your_obfuscation_key_here"
export WEBHOOK_BASE="your_base_url_here"
```

- **WEBHOOK\_OBFUSCATION**: Obfuscates the webhook URL, adding an additional security layer.
- **WEBHOOK\_BASE**: Sets the base domain for the webhook URL. If not specified, `127.0.0.1` is used, which is incompatible with the Telegram API.

### Configuring CSRF Protection

[](#configuring-csrf-protection)

CakePHP includes built-in protection against Cross-Site Request Forgery (CSRF) attacks. However, to allow Telegram webhooks to work properly with TeBo, you need to exclude requests coming from the plugin from this protection.

To do this, adjust the middleware configuration in the `src/Application.php` file. Modify the `middleware` method to include the following logic:

```
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
    $csrf = new CsrfProtectionMiddleware(['httponly' => true]);

    $csrf->skipCheckCallback(function ($request) {
        // Exclude requests from the TeBo plugin from CSRF protection
        if ($request->getParam('plugin') === 'TeBo') {
            return true;
        }
    });

    $middlewareQueue->add($csrf);

    return $middlewareQueue;
}
```

Warning

***Why Is This Necessary?***Telegram cannot send custom headers (such as CSRF tokens), which would cause webhook requests to be rejected if CSRF protection is enabled. By configuring this exclusion, we allow Telegram to interact with our application without compromising the overall security.

Bot Testing
-----------

[](#bot-testing)

Once the webhook and token are configured, the bot should be ready to work. You can test it on Telegram using the following commands:

- `/start`
- `/hello`
- `/about`

Customization
-------------

[](#customization)

To customize the bot's options, you can create a configuration file in `config/tebo.php` with the following structure:

```
