Skip to content

Commit 43503e1

Browse files
committed
Add interface and dummy implementation for command description processing
1 parent dee1027 commit 43503e1

5 files changed

+38
-4
lines changed

src/DependencyInjection/TelegramBotExtension.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Luzrain\TelegramBotBundle\TelegramBot\Command\SetWebhookCommand;
1717
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand;
1818
use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController;
19+
use Luzrain\TelegramBotBundle\TelegramBot\DummyDescriptionProcessor;
1920
use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService;
2021
use Symfony\Component\DependencyInjection\ChildDefinition;
2122
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -89,15 +90,20 @@ public function load(array $configs, ContainerBuilder $container): void
8990
->register('telegram_bot.menu_button_set_commands', ButtonSetCommandsCommand::class)
9091
->setArgument('$botApi', new Reference(BotApi::class))
9192
->setArgument('$commandMetadataProvider', new Reference('telegram_bot.command_metadata_provider'))
93+
->setArgument('$descriptionProcessor', new Reference('telegram_bot.description_processor'))
9294
->addTag('console.command')
9395
;
9496

9597
$container
96-
->register('telegram_bot.menu_button_delete', ButtonDeleteCommand::class)
98+
->register('telegram_bot.menu_button_delete_command', ButtonDeleteCommand::class)
9799
->setArgument('$botApi', new Reference(BotApi::class))
98100
->addTag('console.command')
99101
;
100102

103+
$container
104+
->register('telegram_bot.description_processor', DummyDescriptionProcessor::class)
105+
;
106+
101107
$container->registerAttributeForAutoconfiguration(OnEvent::class, $this->controllerConfigurate(...));
102108
$container->registerAttributeForAutoconfiguration(OnCommand::class, $this->controllerConfigurate(...));
103109
$container->registerAttributeForAutoconfiguration(OnCallback::class, $this->controllerConfigurate(...));

src/TelegramBot/Command/ButtonSetCommandsCommand.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Luzrain\TelegramBotApi\Exception\TelegramApiException;
99
use Luzrain\TelegramBotApi\Method;
1010
use Luzrain\TelegramBotApi\Type;
11+
use Luzrain\TelegramBotBundle\TelegramBot\CommandDescriptionProcessor;
1112
use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
@@ -19,6 +20,7 @@ final class ButtonSetCommandsCommand extends Command
1920
public function __construct(
2021
private BotApi $botApi,
2122
private CommandMetadataProvider $commandMetadataProvider,
23+
private CommandDescriptionProcessor $descriptionProcessor,
2224
) {
2325
parent::__construct();
2426
}
@@ -44,8 +46,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4446
continue;
4547
}
4648

47-
$output->writeln(sprintf("%s\t\t%s", $attr->command, $attr->description));
48-
$commands[] = new Type\BotCommand(command: $attr->command, description: $attr->description);
49+
$description = $this->descriptionProcessor->process($attr->description);
50+
$output->writeln(sprintf("%s\t\t%s", $attr->command, $description));
51+
$commands[] = new Type\BotCommand(command: $attr->command, description: $description);
4952
}
5053

5154
if ($commands === []) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Luzrain\TelegramBotBundle\TelegramBot;
6+
7+
interface CommandDescriptionProcessor
8+
{
9+
public function process(string $description): string;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Luzrain\TelegramBotBundle\TelegramBot;
6+
7+
final class DummyDescriptionProcessor implements CommandDescriptionProcessor
8+
{
9+
public function process(string $description): string
10+
{
11+
return $description;
12+
}
13+
}

tests/ServicesAutowiringTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Luzrain\TelegramBotBundle\TelegramBot\Command\PolllingStartCommand;
1313
use Luzrain\TelegramBotBundle\TelegramBot\Command\SetWebhookCommand;
1414
use Luzrain\TelegramBotBundle\TelegramBot\Command\WebhookInfoCommand;
15+
use Luzrain\TelegramBotBundle\TelegramBot\CommandDescriptionProcessor;
1516
use Luzrain\TelegramBotBundle\TelegramBot\CommandMetadataProvider;
1617
use Luzrain\TelegramBotBundle\TelegramBot\Controller\WebHookController;
1718
use Luzrain\TelegramBotBundle\TelegramBot\LongPollingService;
@@ -45,8 +46,9 @@ public function testServiceAutowiring(): void
4546
$this->assertInstanceOf(DeleteWebhookCommand::class, self::$container->get('telegram_bot.delete_webhook_command'));
4647
$this->assertInstanceOf(PolllingStartCommand::class, self::$container->get('telegram_bot.polling_command'));
4748
$this->assertInstanceOf(ButtonSetCommandsCommand::class, self::$container->get('telegram_bot.menu_button_set_commands'));
48-
$this->assertInstanceOf(ButtonDeleteCommand::class, self::$container->get('telegram_bot.menu_button_delete'));
49+
$this->assertInstanceOf(ButtonDeleteCommand::class, self::$container->get('telegram_bot.menu_button_delete_command'));
4950
$this->assertInstanceOf(UpdateHandler::class, self::$container->get('telegram_bot.update_handler'));
5051
$this->assertInstanceOf(CommandMetadataProvider::class, self::$container->get('telegram_bot.command_metadata_provider'));
52+
$this->assertInstanceOf(CommandDescriptionProcessor::class, self::$container->get('telegram_bot.description_processor'));
5153
}
5254
}

0 commit comments

Comments
 (0)