PHP code example of max-messenger-bot / max-bot-symfony-bundle
1. Go to this page and download the library: Download max-messenger-bot/max-bot-symfony-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
max-messenger-bot / max-bot-symfony-bundle example snippets
return [
// ...
MaxMessenger\Bot\Bundle\MaxBotBundle::class => ['all' => true],
];
// src/Bot/GreetingHandler.php
use MaxMessenger\Bot\Bundle\Contract\MaxBotHandlerInterface;
use MaxMessenger\Bot\MaxBot;
use MaxMessenger\Bot\MaxBot\Event\BotStartedEvent;
use MaxMessenger\Bot\MaxBot\Event\MessageCreatedEvent;
final class GreetingHandler implements MaxBotHandlerInterface
{
public function register(MaxBot $bot): void
{
$bot->onBotStarted(function (BotStartedEvent $event): bool {
$event->sendToChat('Привет! Я бот на Symfony.');
return true;
});
$bot->onMessageCreated(function (MessageCreatedEvent $event): bool {
$event->reply('Ваше сообщение получено.', true);
return true;
});
}
}
yaml
max_bot:
resource: '@MaxBotBundle/config/routes.php'
type: php