lowel / telepath
Telegram bot sdk for laravel inspired by vjik/telegram-bot-api
Fund package maintenance!
Lowel
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
- vjik/telegram-bot-api: ^0.9.1
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^2.5||^3.0
- pestphp/pest-plugin-laravel: ^2.0||^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
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.