diff --git a/docs/README.md b/docs/README.md index 892333f..b8aaa8d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -471,6 +471,7 @@ $api->answerOnCallback( link: null, // Ссылка на сообщение (необязательно) format: null, // Формат сообщения Markdown или HTML (необязательно) notify: true, // Заполните это, если хотите просто отправить одноразовое уведомление пользователю (необязательно) + disableLinkPreview: false, // Не генерировать превью ссылок в новом тексте (необязательно) ); ``` diff --git a/src/Api.php b/src/Api.php index 1c50515..71f1f77 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1214,6 +1214,7 @@ class Api * @param MessageLink|null $link New link for the edited message. * @param MessageFormat|null $format Formatting for the new message text. * @param bool $notify Notification setting for the edited message. + * @param bool $disableLinkPreview If true, server will not generate media preview for links in the updated text. * * @return Result * @throws ClientApiException @@ -1229,6 +1230,7 @@ class Api ?MessageLink $link = null, ?MessageFormat $format = null, bool $notify = true, + bool $disableLinkPreview = false, ): Result { $answerBody = ['notification' => $notification]; if ($text !== null || $attachments !== null || $link !== null) { @@ -1239,7 +1241,7 @@ class Api $this->client->request( self::METHOD_POST, self::ACTION_ANSWERS, - ['callback_id' => $callbackId], + ['callback_id' => $callbackId] + ($disableLinkPreview ? ['disable_link_preview' => true] : []), array_filter($answerBody, fn($value) => $value !== null) ) ); diff --git a/tests/ApiTest.php b/tests/ApiTest.php index d216c61..e993b85 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -1915,6 +1915,31 @@ final class ApiTest extends TestCase $this->assertSame($expectedResult, $result); } + #[Test] + public function answerOnCallbackCanDisableLinkPreview(): void + { + $expectedResult = new Result(true, null); + + $this->clientMock + ->expects($this->once()) + ->method('request') + ->with( + 'POST', + '/answers', + ['callback_id' => 'cb.123.abc', 'disable_link_preview' => true], + ['message' => ['text' => 'See https://dev.max.ru', 'notify' => true]], + ) + ->willReturn(['success' => true]); + + $this->modelFactoryMock + ->expects($this->once()) + ->method('createResult') + ->willReturn($expectedResult); + + $result = $this->api->answerOnCallback('cb.123.abc', text: 'See https://dev.max.ru', disableLinkPreview: true); + $this->assertSame($expectedResult, $result); + } + #[Test] public function answerOnCallbackWithMessageEdit(): void {