itpekov/telegram-message

通过机器人发送消息到Telegram频道

1.0.2 2024-05-25 02:31 UTC

This package is auto-updated.

Last update: 2024-09-08 05:08:48 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

安装

您可以通过composer安装此包

composer require itpekov/telegram-message

.env文件中添加变量

TELEGRAM_CHAT_ID=your_chat_id
TELEGRAM_BOT_TOKEN=your_bot_token

用法

场景1:在任何地方发送消息使用

Telegram::sendMessage('Your message');

场景2:发送异常消息使用

Telegram::sendExceptionMessage($e);

场景3:通过在Handler.php类中添加/更新report方法,发送您应用程序中的所有未处理的异常

use Itpekov\TelegramMessage\Facades\Telegram;

public function report(Throwable $e)
{
    $e = $this->mapException($e);

    if ($this->shouldntReport($e)) {
        return;
    }

    Telegram::sendExceptionMessage($e);

    $this->reportThrowable($e);
}

自定义

可选,您可以使用以下方式发布配置文件

php artisan vendor:publish --provider="Itpekov\TelegramMessage\TelegramMessageServiceProvider" --tag="config"

这是已发布配置文件的内容

return [
    'chat_id' => env('TELEGRAM_CHAT_ID'),
    'bot_token' => env('TELEGRAM_BOT_TOKEN'),
];

可选,您可以使用以下方式发布视图

php artisan vendor:publish --provider="Itpekov\TelegramMessage\TelegramMessageServiceProvider" --tag="views"

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件