westacks / telebot-laravel
Laravel 的 Telebot 适配器
3.2.3
2024-05-15 14:32 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^6.0 || ^7.0
- illuminate/support: ^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- westacks/telebot: ^3.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^3.5 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^8.0 || ^9.0 || ^10.0
- rector/rector: ^0.17
README
TeleBot 是一个用于开发Telegram机器人的PHP库。本项目是 TeleBot 的 Laravel 适配器,用于 TeleBot
文档
库的文档可以在 网站 上找到。
功能
Laravel 支持
库提供了一个 Facade、Artisan 命令和通知通道,以简化在使用 Laravel 开发机器人时的开发过程
门面
TeleBot::getMe(); TeleBot::bot('bot2')->getMe();
自动 webhook 生成
在插入你的机器人令牌后,要创建 webhook,只需执行以下命令
$ php artisan telebot:webhook --setup
为你的 APP_URL
自动生成处理更新的路由
长轮询
如果你不使用 webhook,或者想在本地或测试环境中使用机器人,你可以通过只执行此命令来启动长轮询
$ php artisan telebot:polling
设置命令自动补全
以下命令将自动为所有在 Telegram 服务器上注册的机器人命令设置自动补全
$ php artisan telebot:commands --setup
通知通道
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use WeStacks\TeleBot\Laravel\TelegramNotification; class TelegramNotification extends Notification { public function via($notifiable) { return ['telegram']; } public function toTelegram($notifiable) { return (new TelegramNotification)->bot('bot') ->sendMessage([ 'chat_id' => $notifiable->telegram_chat_id, 'text' => 'Hello, from Laravel\'s notifications!' ]) ->sendMessage([ 'chat_id' => $notifiable->telegram_chat_id, 'text' => 'Second message' ]); } }
日志驱动器
你可以通过将错误发送到某个 Telegram 聊天来记录你的应用程序错误。只需将新的日志驱动器添加到 config/logging.php
'telegram' => [ 'driver' => 'custom', 'via' => \WeStacks\TeleBot\Laravel\Log\TelegramLogger::class, 'level' => 'debug', 'bot' => 'bot', 'chat_id' => env('TELEGRAM_LOG_CHAT_ID') // Any chat where bot can write messages. ]
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。