doge 1 день назад
Родитель
Сommit
98e7de169b

+ 7 - 7
app/Services/TelegramChannelService.php

@@ -256,14 +256,14 @@ class TelegramChannelService
         }
         }
 
 
         $text = $channel['text'];
         $text = $channel['text'];
-        $separateBody = mb_strlen($text) > 1024;
-        $response = $this->sendMedia($telegram, $channel, $params + ['caption' => $separateBody ? '' : $text]);
-        if ($separateBody && isset($response['message_id'])) {
+        if (mb_strlen($text) <= 1024) {
+            return $this->sendMedia($telegram, $channel, $params + ['caption' => $text]);
+        }
+
+        $response = $this->sendMedia($telegram, $channel, ['chat_id' => $params['chat_id'], 'caption' => '']);
+        if (isset($response['message_id'])) {
             try {
             try {
-                $body = $telegram->post('sendMessage', [
-                    'chat_id' => $params['chat_id'],
-                    'text' => $text,
-                ])->getResult();
+                $body = $telegram->post('sendMessage', $params + ['text' => $text])->getResult();
                 if (isset($body['message_id'])) {
                 if (isset($body['message_id'])) {
                     return $response;
                     return $response;
                 }
                 }

+ 1 - 1
docs/前端交付/bot-28/后台/Telegram频道管理-前端接入.md

@@ -58,4 +58,4 @@
 
 
 多语言表单按按钮所在行和列对应中文、英文、越南语。批量保存时提交 `menus: { "zh": { ... }, "en": { ... }, "vi": { ... } }`,每个语言的 `buttons` 为二维字符串数组。未配置的语言可省略,旧客户端也可继续传 `language` 保存单一语言。
 多语言表单按按钮所在行和列对应中文、英文、越南语。批量保存时提交 `menus: { "zh": { ... }, "en": { ... }, "vi": { ... } }`,每个语言的 `buttons` 为二维字符串数组。未配置的语言可省略,旧客户端也可继续传 `language` 保存单一语言。
 
 
-频道消息和私聊开始回复的正文最多 4096 字符。图片或视频的正文超过 1024 字符时,先发媒体,再单独发送完整正文。按钮仍附在媒体消息上。
+频道消息和私聊开始回复的正文最多 4096 字符。图片或视频的正文超过 1024 字符时,先发媒体,再单独发送完整正文。按钮附在正文消息下方。

+ 4 - 1
tests/Integration/TelegramChannelTest.php

@@ -531,9 +531,10 @@ class TelegramChannelTest extends TestCase
         $this->migrate();
         $this->migrate();
         $this->app->register(FilesystemServiceProvider::class);
         $this->app->register(FilesystemServiceProvider::class);
         $text = str_repeat('正文', 600);
         $text = str_repeat('正文', 600);
+        $buttons = [[['text' => '详情', 'url' => 'https://example.com']]];
         $channel = $this->service->save([
         $channel = $this->service->save([
             'chatId' => '@first_channel', 'type' => 'image',
             'chatId' => '@first_channel', 'type' => 'image',
-            'image' => 'https://files.example.test/photo.jpg', 'text' => $text,
+            'image' => 'https://files.example.test/photo.jpg', 'text' => $text, 'button' => $buttons,
         ]);
         ]);
         $this->telegramResult(['message_id' => 18]);
         $this->telegramResult(['message_id' => 18]);
         $this->telegramResult(['message_id' => 19]);
         $this->telegramResult(['message_id' => 19]);
@@ -542,7 +543,9 @@ class TelegramChannelTest extends TestCase
         parse_str((string) $this->requests[0]['request']->getBody(), $media);
         parse_str((string) $this->requests[0]['request']->getBody(), $media);
         parse_str((string) $this->requests[1]['request']->getBody(), $body);
         parse_str((string) $this->requests[1]['request']->getBody(), $body);
         $this->assertSame('', $media['caption']);
         $this->assertSame('', $media['caption']);
+        $this->assertArrayNotHasKey('reply_markup', $media);
         $this->assertSame($text, $body['text']);
         $this->assertSame($text, $body['text']);
+        $this->assertSame(['inline_keyboard' => $buttons], json_decode($body['reply_markup'], true));
 
 
         $this->telegramResult(['message_id' => 20]);
         $this->telegramResult(['message_id' => 20]);
         $this->telegram->append(new Response(400, [], '{"ok":false,"error_code":400,"description":"rejected"}'));
         $this->telegram->append(new Response(400, [], '{"ok":false,"error_code":400,"description":"rejected"}'));