mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-11 06:19:18 +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:
@@ -35,6 +35,8 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\PhotoAttachmentRequ
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ShareAttachmentRequest;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\StickerAttachmentRequest;
|
||||
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;
|
||||
@@ -116,6 +118,8 @@ use RuntimeException;
|
||||
#[UsesClass(ChatMembersList::class)]
|
||||
#[UsesClass(ChatAdmin::class)]
|
||||
#[UsesClass(BotPatch::class)]
|
||||
#[UsesClass(BotCommand::class)]
|
||||
#[UsesClass(BotCommandsInfo::class)]
|
||||
#[UsesClass(ChatPatch::class)]
|
||||
#[UsesClass(VideoAttachmentDetails::class)]
|
||||
#[UsesClass(VideoUrls::class)]
|
||||
@@ -1883,6 +1887,58 @@ final class ApiTest extends TestCase
|
||||
$this->assertSame($expectedResult, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function editBotCommandsSendsCommandsToDedicatedEndpoint(): void
|
||||
{
|
||||
$rawResponseData = [
|
||||
'commands' => [
|
||||
['name' => 'start', 'description' => 'Start the bot'],
|
||||
['name' => 'help', 'description' => null],
|
||||
],
|
||||
];
|
||||
$expectedResult = new BotCommandsInfo([
|
||||
new BotCommand('start', 'Start the bot'),
|
||||
new BotCommand('help', null),
|
||||
]);
|
||||
|
||||
$this->clientMock
|
||||
->expects($this->once())
|
||||
->method('request')
|
||||
->with('PATCH', '/me/commands', [], $rawResponseData)
|
||||
->willReturn($rawResponseData);
|
||||
|
||||
$this->modelFactoryMock
|
||||
->expects($this->once())
|
||||
->method('createBotCommandsInfo')
|
||||
->with($rawResponseData)
|
||||
->willReturn($expectedResult);
|
||||
|
||||
$result = $this->api->editBotCommands([
|
||||
new BotCommand('start', 'Start the bot'),
|
||||
new BotCommand('help', null),
|
||||
]);
|
||||
|
||||
$this->assertSame($expectedResult, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function editBotCommandsSendsAnEmptyList(): void
|
||||
{
|
||||
$this->clientMock
|
||||
->expects($this->once())
|
||||
->method('request')
|
||||
->with('PATCH', '/me/commands', [], ['commands' => []])
|
||||
->willReturn(['commands' => []]);
|
||||
|
||||
$this->modelFactoryMock
|
||||
->expects($this->once())
|
||||
->method('createBotCommandsInfo')
|
||||
->with(['commands' => []])
|
||||
->willReturn(new BotCommandsInfo([]));
|
||||
|
||||
$this->api->editBotCommands([]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function editBotInfoSendsCorrectPatchBody(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user