v2.1.0 2023-05-27 18:06 UTC

This package is auto-updated.

Last update: 2024-08-27 20:53:03 UTC


README

Latest Version on Packagist Total Downloads

安装

通过Composer安装此包。在您的项目终端中运行以下命令

composer require php-telegram-bot/laravel

执行以下命令以将文件夹结构发布到您的Laravel应用程序

php artisan telegram:publish

这还包括一个示例 /start 命令,以帮助您快速开始。

由于我们正在使用php-telegram-bot的数据库部分,因此您应该运行迁移以确保数据库模式被安装

php artisan migrate

并将以下行添加到您的 .env 文件中

TELEGRAM_API_TOKEN=
TELEGRAM_BOT_USERNAME=
TELEGRAM_API_URL=
TELEGRAM_ADMINS=

TELEGRAM_API_TOKENTELEGRAM_BOT_USERNAME 应填充来自 @BotFather 的相应数据

TELEGRAM_API_URL 是可选的,如果您想使用自定义的Bot API服务器,可以填充该服务器的URL。

TELEGRAM_ADMINS 是可选的,并且是一个逗号分隔的Telegram用户ID列表,该列表将传递给php-telegram-bot的 enableAdmins 命令,以启用这些用户的管理员命令。

之后,您可以通过运行 php artisan telegram:set-webhook 来启动,如果您的开发服务器可以从外部访问或您正在使用自定义的bot api服务器。

或运行 php artisan telegram:fetch 以通过轮询开始获取您的更新。

⚠️ 注意,如果您更改了代码,必须取消并重新启动 telegram:fetch 命令。

用法

对于此Laravel包的进一步基本配置,您不需要创建任何配置文件。

用于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 Server注销的Artisan终端命令

# Sends a logout to the currently registered Telegram Server
php artisan telegram:logout

用于关闭Telegram Server的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

致谢

许可证

请参阅许可证文件以获取更多信息。