Merge pull request #43 from smotim/fix/me-commands

feat: add editBotCommands for PATCH /me/commands, deprecate editBotInfo
This commit is contained in:
Alex
2026-10-01 08:33:26 +03:00
committed by GitHub
9 changed files with 213 additions and 3 deletions
+32
View File
@@ -17,6 +17,8 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\AudioAttachmentRequ
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\FileAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\PhotoAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\VideoAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\BotPatch;
use BushlanovDev\MaxMessengerBot\Models\Chat;
@@ -61,6 +63,7 @@ class Api
private const string METHOD_PUT = 'PUT';
private const string ACTION_ME = '/me';
private const string ACTION_ME_COMMANDS = '/me/commands';
private const string ACTION_SUBSCRIPTIONS = '/subscriptions';
private const string ACTION_MESSAGES = '/messages';
private const string ACTION_UPLOADS = '/uploads';
@@ -252,6 +255,31 @@ class Api
);
}
/**
* Edits the bot commands shown to users as hints when they type "/".
*
* Example: editBotCommands([new BotCommand('start', 'Start the bot'), new BotCommand('help', 'Help')]);
*
* @param BotCommand[] $commands Up to 32 commands.
*
* @return BotCommandsInfo
* @throws ClientApiException
* @throws NetworkException
* @throws ReflectionException
* @throws SerializationException
*/
public function editBotCommands(array $commands): BotCommandsInfo
{
return $this->modelFactory->createBotCommandsInfo(
$this->client->request(
self::METHOD_PATCH,
self::ACTION_ME_COMMANDS,
[],
['commands' => array_map(static fn(BotCommand $command) => $command->toArray(), $commands)],
)
);
}
/**
* List of all active webhook subscriptions.
*
@@ -1099,6 +1127,10 @@ class Api
*
* Example: editBotInfo(new BotPatch(name: 'New Bot Name', description: null));
*
* @deprecated The API no longer accepts `PATCH /me` and answers "Path /me is not recognized".
* Set commands with editBotCommands(); name, description and photo are edited
* on the MAX partner platform.
*
* @param BotPatch $botPatch
*
* @return BotInfo
+14
View File
@@ -32,6 +32,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\StickerAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\VideoAttachment;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Chat;
use BushlanovDev\MaxMessengerBot\Models\ChatList;
@@ -106,6 +107,19 @@ readonly class ModelFactory
return Result::fromArray($data);
}
/**
* Commands of the current bot.
*
* @param array<string, mixed> $data
*
* @return BotCommandsInfo
* @throws ReflectionException
*/
public function createBotCommandsInfo(array $data): BotCommandsInfo
{
return BotCommandsInfo::fromArray($data);
}
/**
* Information about the current bot.
*
+22
View File
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
/**
* Bot commands information.
*/
final readonly class BotCommandsInfo extends AbstractModel
{
/**
* @param BotCommand[]|null $commands Commands supported by the bot (up to 32 elements).
*/
public function __construct(
#[ArrayOf(BotCommand::class)]
public ?array $commands,
) {
}
}
+2
View File
@@ -17,6 +17,8 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequ
* @property-read BotCommand[]|null $commands
* @property-read PhotoAttachmentRequestPayload|null $photo
* @property-read string|null $name @deprecated Use first_name
*
* @deprecated The API no longer accepts `PATCH /me`. Use Api::editBotCommands() for commands.
*/
final readonly class BotPatch extends AbstractPatchModel
{