Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Command Handling for Telegram Bot (Issue #13) #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Hello/Telegram/Command/HelloCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@

namespace App\Hello\Telegram\Command;

use Psr\Log\LoggerInterface;
use BoShurik\TelegramBotBundle\Telegram\Command\AbstractCommand;
use BoShurik\TelegramBotBundle\Telegram\Command\PublicCommandInterface;
use TelegramBot\Api\BotApi;
use TelegramBot\Api\Types\Update;

class HelloCommand extends AbstractCommand implements PublicCommandInterface
{
private $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

public function getName(): string
{
return '/hello';
Expand All @@ -30,6 +38,7 @@ public function getDescription(): string

public function execute(BotApi $api, Update $update): void
{
$this->logger->info('Executing HelloCommand');
preg_match(self::REGEXP, $update->getMessage()->getText(), $matches);
$who = !empty($matches[3]) ? $matches[3] : 'World';

Expand Down
9 changes: 9 additions & 0 deletions src/Help/Telegram/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@

namespace App\Help\Telegram\Command;

use Psr\Log\LoggerInterface;
use BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand as BaseCommand;
use TelegramBot\Api\Types\Update;

class HelpCommand extends BaseCommand
{
private $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

public function isApplicable(Update $update): bool
{
$this->logger->info('Checking applicability of HelpCommand');
return $update->getMessage() !== null;
}
}