usmonaliyev / laravel-telegram-notifier
此包将错误和消息发送到您的Telegram群组或聊天。
v1.3.0
2024-07-23 09:46 UTC
Requires
- php: ^7.4|^8.1
- illuminate/contracts: ^10.0|^11.0
README
此包将错误和消息发送到您的Telegram群组或聊天。
截图
安装
使用composer安装此项目
composer require usmonaliyev/laravel-telegram-notifier
要控制它,创建配置文件
php artisan vendor:publish --provider="Usmonaliyev\LaravelTelegramNotifier\LaravelTelegramNotifierServiceProvider"
将您的机器人令牌和接收聊天ID添加到.env
文件。
TELEGRAM_NOTIFIER_BOT_TOKEN=
CHAT_ID=
TELEGRAM_NOTIFIER_ERROR_LOG=false
TELEGRAM_NOTIFIER_RESPONSIBLE=@someone
我建议您仅在生产环境中使用它。为此,将.env
文件中的APP_ENV
值更改为生产。
APP_ENV=production
如果您正在运行本地服务器(在Terminal中使用control + c停止)并在localhost:8000
上使用php artisan serve
,则需要停止本地服务器并再次运行php artisan serve
以启动它 - 然后您的更改将生效。
配置
在您的config
文件夹中存在laravel-telegram-notifier.php
文件。如果您想将消息发送到两个或三个聊天ID,请将聊天ID添加到laravel-telegram-notifier.php
文件中的chat_ids
数组。
"chat_ids" => [env("CHAT_ONE_ID"), env("CHAT_TWO_ID"), env("CHAT_THREE_ID")],
消息头,默认值为.env
文件中的APP_NAME
。我建议文本以\n结尾
"message_title" => env("APP_NAME", "laravel-telegram-notifier") . "\n",
"message" => [
MessageSection::REQUEST => [
/**
* Get all of the input and files for the request.
*/
"body" => RequestMessageBuilder::ALL,
/**
* Returns the path being requested relative to the executed script.
*/
"path_info" => RequestMessageBuilder::PATH_INFO,
/**
* Get the client user agent.
*/
"user_agent" => RequestMessageBuilder::USER_AGENT,
/**
* Get the client IP address.
*/
"ip" => RequestMessageBuilder::IP,
],
MessageSection::ERROR => [
/**
* Returns the Exception message as a string.
*/
"message" => ErrorMessageBuilder::GET_MESSAGE,
/**
* Gets the Exception code
*/
"code" => ErrorMessageBuilder::GET_CODE,
/**
* Gets the file in which the exception was created
*/
"file" => ErrorMessageBuilder::GET_FILE,
/**
* Gets the Exception code
*/
"code" => ErrorMessageBuilder::GET_CODE,
/**
* Gets the line in which the exception was created
*/
"line" => ErrorMessageBuilder::GET_LINE,
]
]
运行测试
为了验证包已完全安装并正常工作,您可以运行以下命令,这将帮助您创建一个新模拟错误。
php artisan notify:check
如果Telegram没有收到消息,请检查.env
文件中的APP_ENV
值是否为生产。如果您处于开发环境,请使用php artisan serve
命令重新启动应用程序。在生产模式下,您可以使用php artisan config:clear
命令从.env文件中加载配置。