lowel/telepath

Telegram bot sdk for laravel inspired by vjik/telegram-bot-api

Fund package maintenance!
Lowel

0.2.2 2025-07-30 21:15 UTC

This package is auto-updated.

Last update: 2025-07-30 21:16:20 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Telegram bot SDK for Laravel inspired by vjik/telegram-bot-api.

SDK supports routes and long pooling \ webhook handling

Installation

You can install the package via composer:

composer require lowel/telepath

You can publish the config file with:

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

This is the contents of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | Telepath Configuration
    |--------------------------------------------------------------------------
    |
    | This file is for storing the configuration of the Telepath package.
    | You can set your bot token and other settings here.
    |
    */

    'token' => env('TELEPATH_TOKEN'),
    'base_uri' => env('TELEPATH_BASE_URL', 'https://api.TELEPATH.org'),

    /*
     * Routes path
     */
    'routes' => base_path(env('TELEPATH_ROUTES', 'routes/TELEPATH.php')),

    'profile' => 'default',

    'profiles' => [
        'default' => [
            'offset' => (int) env('TELEPATH_OFFSET', 0),
            'timeout' => (int) env('TELEPATH_TIMEOUT', 30),
            'allowed_updates' => explode(',', env('TELEPATH_ALLOWED_UPDATES', '*')),
        ],
    ],
];

Usage

use Lowel\Telepath\Facades\Telepath;
use Vjik\TelegramBot\Api\TelegramBotApi;
use Vjik\TelegramBot\Api\Type\Update\Update;

Telepath::middleware(function (TelegramBotApi $telegramBotApi, Update $update, callable $callback) {
    logger()->info('Middleware in');
    $callback();
    logger()->info('Middleware out');    
})->group(function () {
    Telepath::on(function (TelegramBotApi $telegramBotApi, Update $update) {
        $telegramBotApi->sendMessage($update->getMessage()->getChat()->getId(), 'Hello, world!');
    }, pattern: '/start');

    Telepath::on(function (TelegramBotApi $telegramBotApi, Update $update) {
        $message = $update->getMessage();
        if ($message) {
            $telegramBotApi->sendMessage($message->getChat()->getId(), $message->getText());
        }
    }, pattern: '/echo');
});

Start up:

php artisan telepath:run

Or using webhook:

php artisan telepath:hook:set https://your-domain.com/api/webhook

License

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