mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-06 20:10:31 +00:00
Add disableLinkPreview to answerOnCallback
POST /answers got the disable_link_preview query parameter in August 2026. It is sent only when true, so default requests are unchanged.
This commit is contained in:
@@ -471,6 +471,7 @@ $api->answerOnCallback(
|
||||
link: null, // Ссылка на сообщение (необязательно)
|
||||
format: null, // Формат сообщения Markdown или HTML (необязательно)
|
||||
notify: true, // Заполните это, если хотите просто отправить одноразовое уведомление пользователю (необязательно)
|
||||
disableLinkPreview: false, // Не генерировать превью ссылок в новом тексте (необязательно)
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
+3
-1
@@ -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)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user