Comments (7)
You're welcome! Nice bot integration repo! I've used it in my diploma project in university:)
Slava Ukraine! 🇺🇦
from telebot.
I've changed in Handler.php following:
use Monolog\LogRecord;
public function write(LogRecord $record): void
private function formatText(LogRecord $record): string
return view('telebot::log', array_merge(['formatted' => $record->formatted], $record->toArray(), [
Here is entire updated class:
<?php
namespace WeStacks\TeleBot\Laravel\Log;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
use Monolog\Logger;
use WeStacks\TeleBot\TeleBot;
class Handler extends AbstractProcessingHandler
{
/**
* Bot instance.
*
* @var TeleBot
*/
protected $bot;
/**
* Chat id to send log message.
*
* @var string
*/
protected $chat_id;
/**
* App name.
*
* @var string
*/
protected $app;
/**
* App env.
*
* @var string
*/
protected $env;
public function __construct(array $config)
{
$level = Logger::toMonologLevel($config['level']);
parent::__construct($level, true);
// define variables for making Telegram request
$this->bot = app('telebot')->bot($config['bot'] ?? null);
$this->chat_id = $config['chat_id'];
// define variables for text message
$this->app = config('app.name');
$this->env = config('app.env');
}
public function write(LogRecord $record): void
{
$textChunks = str_split($this->formatText($record), 4096);
foreach ($textChunks as $textChunk) {
$this->sendMessage($textChunk);
}
}
/**
* {@inheritDoc}
*/
protected function getDefaultFormatter(): FormatterInterface
{
return new LineFormatter("%message% %context% %extra%\n");
}
private function formatText(LogRecord $record): string
{
return view('telebot::log', array_merge(['formatted' => $record->formatted], $record->toArray(), [
'app' => $this->app,
'env' => $this->env,
]))->render();
}
private function sendMessage(string $text): void
{
$this->bot->exceptions(false)->async(false)->sendMessage([
'chat_id' => $this->chat_id,
'parse_mode' => 'html',
'text' => $text,
]);
}
}
from telebot.
Here is my logging config
'telegram' => [
'formatter' => Monolog\Formatter\LineFormatter::class,
'driver' => 'custom',
'via' => TelegramLogger::class,
'level' => 'debug',
'bot' => 'bot',
'chat_id' => env('TELEGRAM_LOG_CHAT_ID')
]
Idk if formatter
line is necessary
from telebot.
This is just a hotfix for my version, please do not copy&paste.
Save backward compatibility
from telebot.
Hello, thanks a lot for your bug request. This seems to be changed in Monolog v3. Fixed in fa70e8c
from telebot.
Small notice about your change commit. You've written type hint for array and LogRecord object, but you do ->toArray() for object, but when array will be passed it would throw an error that it is not possible to call toArray method for array.
I'd write some method that would prepare data and you can check whether it is array or object and always return array for format method :)
from telebot.
Small notice about your change commit. You've written type hint for array and LogRecord object, but you do ->toArray() for object, but when array will be passed it would throw an error that it is not possible to call toArray method for array. I'd write some method that would prepare data and you can check whether it is array or object and always return array for format method :)
There is a check if passed record is an instance of LogRecord
, so there will be no error
if (is_a($record, LogRecord::class)) {
$record = array_merge($record->toArray(), ['formatted' => $record->formatted]);
}
from telebot.
Related Issues (20)
- Wrong response from the webhook: 403 Forbidden HOT 1
- Clean up political shit from where it's fucked up like no place HOT 1
- Method answerInlineQuery missing in PHPDoc
- WebApps support HOT 1
- Invalid handler type HOT 1
- Error Handling HOT 4
- get error when use many hendlers in laravel HOT 2
- How can I make a Menu button which opening a web app? HOT 2
- Ошибка в документации HOT 1
- Can't run 2.0 on PHP 7.4 HOT 1
- Tests are failing when using handleUpdate() in loop HOT 2
- Cannot cast value of type NULL to type string in Inline mode HOT 3
- [Cannot cast value of type NULL to type string error in Inline mode] HOT 6
- Upgrading from v1 to v2.4 HOT 2
- [BUG] message thread not found HOT 2
- Can you provide an example of a bot with laravel? HOT 1
- [BUG] Argument #1 ($bot) must be of type TeleBot, WeStacks\TeleBot\TeleBot given HOT 1
- Error in RequestInputHandler while executing $this->acceptInput()
- Laravel telebot config on database
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telebot.