cloud-castle / laravel-telegram-bot
将 PHP Telegram Bot 集成到 LaravelTelegramBot 中。
Requires
- ext-pcntl: *
- illuminate/support: ~7|~8|~9|~10
- longman/telegram-bot: ^0.81
Requires (Dev)
- phpunit/phpunit: ~9.0
- symfony/process: ^5.3
README
安装
通过 Composer 安装此软件包。在项目的终端运行以下命令
composer require cloud-castle/cloud-castle
执行以下命令,将文件夹结构发布到您的 LaravelTelegramBot 应用程序
php artisan telegram:publish
这还包括一个用于快速开始的示例 /start
命令。
由于我们使用了 cloud-castle 的数据库部分,因此您应该运行迁移以安装数据库模式
php artisan migrate
并将以下行添加到您的 .env 文件中
TELEGRAM_API_TOKEN= TELEGRAM_BOT_USERNAME= TELEGRAM_API_URL= TELEGRAM_ADMINS=
TELEGRAM_API_TOKEN
和 TELEGRAM_BOT_USERNAME
应填写来自 @BotFather 的对应数据
TELEGRAM_API_URL
是可选的,如果您想使用自定义的 Bot API 服务器,可以填写该服务器的 URL。
TELEGRAM_ADMINS
是可选的,是一个以逗号分隔的 Telegram 用户 ID 列表,这些 ID 将传递给 cloud-castle 的 enableAdmins
命令,以启用这些用户的管理员命令。
之后,如果您的开发服务器可以从外部访问或您正在使用自定义的 bot api 服务器,您可以运行 php artisan telegram:set-webhook
。
或者运行 php artisan telegram:fetch
以通过轮询开始获取您的更新。
⚠️ 请注意,如果更改了您的代码,您必须取消并重新启动 telegram:fetch
命令。
用法
对于此 LaravelTelegramBot 软件包的进一步基本配置,您不需要创建任何配置文件。
用于 Webhook 用法的 Artisan 终端命令(请记住,您需要一个 HTTPS 服务器来使用它)
# Use this method to specify a url and receive incoming updates via an outgoing webhook php artisan telegram:set-webhook # List of available options: # --d|drop-pending-updates : Drop all pending updates # --a|all-update-types : Explicitly allow all updates (including "chat_member") # --allowed-updates= : Define allowed updates (comma-seperated) # Use this method to remove webhook integration if you decide to switch back to getUpdates php artisan telegram:delete-webhook # List of available options: # --d|drop-pending-updates : Pass to drop all pending updates
用于 Telegram getUpdates 方法的 Artisan 终端命令
# Fetches Telegram updates periodically php artisan telegram:fetch # List of available options: # --a|all-update-types : Explicitly allow all updates (including "chat_member") # --allowed-updates= : Define allowed updates (comma-seperated)
用于从 Telegram 服务器注销的 Artisan 终端命令
# Sends a logout to the currently registered Telegram Server
php artisan telegram:logout
用于关闭 Telegram 服务的 Artisan 终端命令
# Sends a close to the currently registered Telegram Server
php artisan telegram:close
用于在项目中发布 Telegram 命令文件夹结构的 Artisan 终端命令
# Publishes folder structure for Telegram Commands # Default StartCommand class will be created php artisan telegram:publish
用于在项目中创建新的 Telegram 命令类的 Artisan 终端命令
# Create a new Telegram Bot Command class # e.g. php artisan make:telegram-command Menu --> will make User command class MenuCommand # e.g. php artisan make:telegram-command Genericmessage --system --> will make System command class GenericmessageCommand php artisan make:telegram-command # List of available options: # name : Name of the Telegram Command # --a|admin : Generate a AdminCommand # --s|system : Generate a SystemCommand # Without admin or system option default User command will be created
鸣谢
许可证
有关更多信息,请参阅 许可证文件。