locky42/telegram-logger
最新稳定版本:1.2.2
Composer 安装命令:
composer require locky42/telegram-logger
包简介
A PSR-4 compatible logger for sending messages to Telegram via Bot API.
README 文档
README
Simple and reliable service for logging messages to Telegram with PSR-4 autoloading support.
Installation
composer require locky42/telegram-logger
Usage
Basic Usage
<?php use Locky42\TelegramLogger\TelegramLogger; // Initialize the logger $logger = new TelegramLogger('YOUR_CHAT_ID', 'YOUR_BOT_TOKEN'); // Send a message $logger->log('Test message'); // Send a message with log level $logger->info('Information message'); $logger->warning('Warning'); $logger->error('Error');
Configuration
<?php use Locky42\TelegramLogger\TelegramLogger; use Locky42\TelegramLogger\Config\TelegramConfig; $config = new TelegramConfig([ 'bot_token' => 'YOUR_BOT_TOKEN', 'chat_id' => 'YOUR_CHAT_ID', 'parse_mode' => 'HTML', // or 'Markdown' 'timeout' => 30, 'thread_id' => 123456789 // optional: message thread ID for group discussions ]); $logger = new TelegramLogger($config);
Getting Bot Token
- Message @BotFather in Telegram
- Use the
/newbotcommand - Give your bot a name
- Get the bot token
Getting Chat ID
- Add the bot to the chat
- Send any message to the chat
- Go to:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find
chat.idin the response
Getting Thread ID
For group discussions with threads:
- Enable topics in your group (Group Settings > Topics)
- Create a new topic/thread in the group
- Send a message in that thread
- Go to:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find
message_thread_idin the response
Testing
composer test
License
MIT License
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-29