mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-11-25 21:24:22 +00:00
Add editBotCommands for PATCH /me/commands, deprecate editBotInfo
The API no longer accepts PATCH /me: it answers "Path /me is not recognized", so editBotInfo() fails, including for commands. Commands now have their own endpoint, PATCH /me/commands (editMyCommands in the official schema); bot name, description and photo are edited on the MAX partner platform. - Api::editBotCommands(BotCommand[]): BotCommandsInfo - BotCommandsInfo model and ModelFactory::createBotCommandsInfo() - editBotInfo() and BotPatch marked @deprecated - README coverage map and docs updated
This commit is contained in:
+32
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user