Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os:
- ubuntu-latest
php:
- "8.1"
- "8.5"
steps:
-
name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os:
- ubuntu-latest
php:
- "8.0"
- "8.5"
steps:
-
name: Checkout
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
deps:
- latest
- lowest
Expand Down Expand Up @@ -49,6 +50,10 @@ jobs:
name: Update composer
run: composer self-update

-
name: Remote tools
run: composer remove psalm/plugin-symfony vimeo/psalm friendsofphp/php-cs-fixer --dev

-
name: Install dependencies with composer
if: matrix.deps == 'latest'
Expand Down
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
'yoda_style' => false,
'declare_strict_types' => false,
'void_return' => false,
'phpdoc_align' => [],
'phpdoc_align' => [
'align' => 'left',
],
'phpdoc_to_comment' => false,
'single_line_comment_spacing' => false,
'nullable_type_declaration_for_default_null_value' => true,
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
CHANGELOG
=========

6.0.2 (2025-12-15)
------------------

* Add Symfony 8 support
* Add php 8.5 support

6.0.1 (2025-07-10)
------------------

* Add php 8.4 support

6.0.0 (2024-09-27)
------------------

Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
"php": "^8.0",
"ext-curl": "*",
"ext-json": "*",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"telegram-bot/api": "^2.3.14"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~3.23.0",
"friendsofphp/php-cs-fixer": "~3.92.0",
"symfony/phpunit-bridge": "^7.0.1",
"symfony/security-http": "^5.4 || ^6.0 || ^7.0",
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
"symfony/messenger": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"vimeo/psalm": "~4.30.0",
"psalm/plugin-symfony": "^4.0"
"symfony/security-http": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/http-client": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/messenger": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"vimeo/psalm": "~6.14.2",
"psalm/plugin-symfony": "^5.2.7"
},
"suggest": {
"symfony/security-guard": "Required to implement user authentication through Telegram",
Expand Down
10 changes: 3 additions & 7 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
<ReservedWord>
<errorLevel type="suppress">
<directory name="src"/>
<directory name="tests"/>
</errorLevel>
</ReservedWord>
<UnusedClass errorLevel="suppress" />
<PossiblyUnusedMethod errorLevel="suppress" />
</issueHandlers>

<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
Expand Down
4 changes: 4 additions & 0 deletions src/Authenticator/TelegramAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public function __construct(
) {
}

#[\Override]
public function supports(Request $request): ?bool
{
$route = $request->attributes->get('_route');

return $route === $this->guardRoute;
}

#[\Override]
public function authenticate(Request $request): Passport
{
$credentials = $request->query->all();
Expand All @@ -66,6 +68,7 @@ public function authenticate(Request $request): Passport
}));
}

#[\Override]
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
{
if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) {
Expand All @@ -75,6 +78,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
return new RedirectResponse($this->urlGenerator->generate($this->defaultTargetRoute));
}

#[\Override]
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
if ($this->loginRoute) {
Expand Down
4 changes: 3 additions & 1 deletion src/BoShurikTelegramBotBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@

final class BoShurikTelegramBotBundle extends Bundle
{
#[\Override]
public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new CommandCompilerPass());
}

#[\Override]
public function getContainerExtension(): ?ExtensionInterface
{
if (null === $this->extension) {
$this->extension = new BoShurikTelegramBotExtension();
}

return $this->extension;
return $this->extension ?: null;
}
}
3 changes: 2 additions & 1 deletion src/Command/UpdatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(private Telegram $telegram)
parent::__construct();
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -33,9 +34,9 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string|null $bot */
$bot = $input->getArgument('bot');
if ($bot) {
$this->telegram->processUpdates($bot);
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Webhook/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(private BotLocator $botLocator)
parent::__construct();
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -35,11 +36,11 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var string|null $bot */
$bot = $input->getArgument('bot');
if ($bot) {
$api = $this->botLocator->get($bot);
Expand All @@ -56,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function printWebhookInfo(SymfonyStyle $io, string $name, BotApi $api): void
{
$io->block(sprintf('Bot "%s"', $name));
$io->block(\sprintf('Bot "%s"', $name));

$info = $api->getWebhookInfo();

Expand Down
14 changes: 7 additions & 7 deletions src/Command/Webhook/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(private BotLocator $botLocator, private UrlGenerator
parent::__construct();
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -51,22 +52,21 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$certificateFile = null;
if ($certificate = $input->getArgument('certificate')) {
if (!is_file($certificate) || !is_readable($certificate)) {
throw new \RuntimeException(sprintf('Can\'t read certificate file "%s"', $certificate));
throw new \RuntimeException(\sprintf('Can\'t read certificate file "%s"', $certificate));
}

$certificateFile = new \CURLFile($certificate);
}

/** @var string|null $urlOrHostname */
$urlOrHostname = $input->getArgument('urlOrHostname');
/** @var string|null $bot */
$bot = $input->getOption('bot');

$allowedUpdates = $input->getOption('allowedUpdateType');
Expand Down Expand Up @@ -108,7 +108,7 @@ private function setWebhook(
?\CURLFile $certificateFile = null,
?array $allowedUpdates = null
): bool {
$io->block(sprintf('Bot "%s"', $name));
$io->block(\sprintf('Bot "%s"', $name));

if (!$urlOrHostname) {
$url = $this->urlGenerator->generate('_telegram_bot_webhook', [
Expand All @@ -127,17 +127,17 @@ private function setWebhook(
} catch (RouteNotFoundException $e) {
$helpUrl = 'https://github.com/BoShurik/TelegramBotBundle#add-routing-for-webhook';
$message = "We could not find the webhook route. Read on\n<options=bold>%s</>\nhow to add the route or use symfony/flex.";
$io->block(messages: sprintf($message, $helpUrl), escape: false);
$io->block(messages: \sprintf($message, $helpUrl), escape: false);

return false;
}
} else {
$url = $urlOrHostname;
}

$api->setWebhook($url, $certificateFile, null, self::MAX_CONNECTIONS, json_encode($allowedUpdates));
$api->setWebhook($url, $certificateFile, null, self::MAX_CONNECTIONS, (string) json_encode($allowedUpdates));

$message = sprintf('Webhook URL has been set to <options=bold>%s</>', $url);
$message = \sprintf('Webhook URL has been set to <options=bold>%s</>', $url);
$io->block($message, 'OK', 'fg=black;bg=green', ' ', true, false);

return true;
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Webhook/UnsetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(private BotLocator $botLocator)
parent::__construct();
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -35,11 +36,11 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var string|null $bot */
$bot = $input->getArgument('bot');
if ($bot) {
$api = $this->botLocator->get($bot);
Expand All @@ -55,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function deleteWebhook(SymfonyStyle $io, string $name, BotApi $api): void
{
$io->block(sprintf('Bot "%s"', $name));
$io->block(\sprintf('Bot "%s"', $name));

$api->deleteWebhook();

Expand Down
16 changes: 13 additions & 3 deletions src/DependencyInjection/BoShurikTelegramBotExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Contracts\HttpClient\HttpClientInterface as SymfonyHttpClientInterface;
use TelegramBot\Api\BotApi;
use TelegramBot\Api\Http\CurlHttpClient;
use TelegramBot\Api\Http\HttpClientInterface;
use TelegramBot\Api\Http\SymfonyHttpClient;

/**
* @psalm-suppress InternalClass
*/
final class BoShurikTelegramBotExtension extends Extension
{
private const BOT_API_ID_TEMPLATE = 'boshurik_telegram_bot.api.bot.%s';

#[\Override]
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand All @@ -45,25 +49,30 @@ public function load(array $configs, ContainerBuilder $container): void

$defaultBot = $config['api']['default_bot'];

/** @psalm-suppress UndefinedClass */
if (interface_exists(HttpClientInterface::class)) {
/** @psalm-suppress UndefinedClass */
if (interface_exists(SymfonyHttpClientInterface::class)) {
/** @psalm-suppress UndefinedClass */
$httpClient = new Definition(SymfonyHttpClient::class, [
new Reference(SymfonyHttpClientInterface::class),
]);
} else {
/** @psalm-suppress UndefinedClass */
$httpClient = new Definition(CurlHttpClient::class);
$httpClient->addMethodCall('setProxy', [new Parameter('boshurik_telegram_bot.api.proxy')]);
$httpClient->addMethodCall('setOption', [\CURLOPT_TIMEOUT, new Parameter('boshurik_telegram_bot.api.timeout')]);
}

/** @psalm-suppress UndefinedClass */
$container->setDefinition(HttpClientInterface::class, $httpClient);
}

$bots = [];
$registries = [];
foreach ($config['api']['bots'] as $name => $bot) {
$botId = sprintf(self::BOT_API_ID_TEMPLATE, $name);
$registryId = sprintf(CommandCompilerPass::REGISTRY_ID_TEMPLATE, $name);
$botId = \sprintf(self::BOT_API_ID_TEMPLATE, $name);
$registryId = \sprintf(CommandCompilerPass::REGISTRY_ID_TEMPLATE, $name);

$container
->setDefinition(
Expand Down Expand Up @@ -123,6 +132,7 @@ public function load(array $configs, ContainerBuilder $container): void
;
}

#[\Override]
public function getAlias(): string
{
return 'boshurik_telegram_bot';
Expand Down
Loading
Loading