1. Go to this page and download the library: Download klev-o/telegram-bot-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
useKlev\TelegramBotApi\Telegram;
useKlev\TelegramBotApi\Events\EditedMessageEvent;
useMonolog\Handler\StreamHandler;
useMonolog\Logger;
ar/logs/app.log'));
$bot = new Telegram('your personal token');
$bot->setEnableEvents(true);
$bot->on(EditedMessageEvent::class, static function(EditedMessageEvent $event) use ($logger) {
//do something with $event
$logger->info('id from event', [$event->update_id])
$logger->info('payload from event', [$event->payload])
});
//For this example, let's assume that the incoming webhook populated the message field in the object
$updates = $bot->getWebhookUpdates();
//Then the `MessageEvent` will fire and the fields will be filled accordingly:
$event->update_id === $updates->update_id
$event->payload === $updates->message
useKlev\TelegramBotApi\Telegram;
useKlev\TelegramBotApi\Events\MessageEvent;
useMonolog\Handler\StreamHandler;
useMonolog\Logger;
ate an object
LoggerInterface::class => function(\DI\Container $c){
$log = new Logger('App');
$log->pushHandler(new StreamHandler('../var/logs/app.log'));
return $log;
},
//specify the rules on how to create an object
MessageReceivedListener::class => function(\DI\Container $c){
returnnew MessageReceivedListener($c->get(LoggerInterface::class));
}
]);
$container = $builder->build();
//Instead of using an anonymous function, we can now use a custom class, into which,//if necessary, we can pull everything we need (working with the database, sending by mail, etc.)classMessageReceivedListener{
private Logger $logger;
publicfunction__construct(Logger $logger){
$this->logger = $logger;
}
publicfunction__invoke(MessageEvent $event){
$this->log->info('Using invocable class', (array)$event->payload);
}
}
$bot = new Telegram('your personal token');
$bot->setEnableEvents(true);
$bot->on(MessageEvent::class, $container->get(MessageReceivedListener::class));
$bot->getWebhookUpdates();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.