@foxden-app/foxclaw 0.5.32 → 0.5.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/channels/bridge_messaging_router.d.ts +2 -0
- package/dist/channels/bridge_messaging_router.js +12 -0
- package/dist/channels/telegram/telegram_messaging_port.d.ts +2 -0
- package/dist/channels/telegram/telegram_messaging_port.js +9 -0
- package/dist/controller/controller.d.ts +3 -0
- package/dist/controller/controller.js +124 -13
- package/dist/controller/presentation.js +1 -6
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.js +3 -0
- package/dist/telegram/gateway.d.ts +10 -0
- package/dist/telegram/gateway.js +34 -0
- package/dist/telegram/html.d.ts +8 -0
- package/dist/telegram/html.js +31 -0
- package/dist/telegram/rich.d.ts +13 -0
- package/dist/telegram/rich.js +12 -0
- package/docs/telegram-rich-messages.md +99 -0
- package/docs/user-manual.md +4 -0
- package/docs/zh/telegram-rich-messages.md +125 -0
- package/docs/zh/user-manual.md +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable FoxClaw changes are listed here. Each release note is bilingual so GitHub Releases and the npm package are useful to both Chinese and English readers.
|
|
4
4
|
|
|
5
|
+
## 0.5.33 - 2026-06-16
|
|
6
|
+
|
|
7
|
+
### 中文
|
|
8
|
+
- 新增 Telegram Rich Message 适配专项盘点,明确现有 HTML 通道、Bot API 10.1 rich message 能力、FoxClaw 可用功能面和分阶段接入路线。
|
|
9
|
+
- 接入 `sendRichMessage` / rich HTML 发送链路,新增 `/rich` 诊断命令用于在 Telegram 客户端直接查看 heading、table、details、pre/code、list 的 RichMessage 渲染效果。
|
|
10
|
+
- 集中 Telegram HTML 转义与常用标签 helper,并把 `/diff` 改为优先使用 RichMessage details + diff code block;发送失败时回退到原 Telegram HTML 折叠展示。
|
|
11
|
+
|
|
12
|
+
### English
|
|
13
|
+
- Added a Telegram Rich Message adaptation check covering the current HTML path, Bot API 10.1 rich message capabilities, FoxClaw candidate surfaces, and a phased rollout plan.
|
|
14
|
+
- Wired the `sendRichMessage` / rich HTML send path and added `/rich` as a diagnostic command for checking heading, table, details, pre/code, and list rendering in Telegram clients.
|
|
15
|
+
- Centralized Telegram HTML escaping/tag helpers and changed `/diff` to prefer RichMessage details plus a diff code block, falling back to the previous Telegram HTML collapsible rendering if rich sending fails.
|
|
16
|
+
|
|
5
17
|
## 0.5.32 - 2026-06-11
|
|
6
18
|
|
|
7
19
|
### 中文
|
|
@@ -15,8 +15,10 @@ export declare class BridgeMessagingRouter {
|
|
|
15
15
|
private requireWeixinTransport;
|
|
16
16
|
sendPlain(scopeId: string, text: string, keyboard?: InlineKeyboard): Promise<number>;
|
|
17
17
|
sendHtml(scopeId: string, text: string, keyboard?: InlineKeyboard): Promise<number>;
|
|
18
|
+
sendRichHtml(scopeId: string, html: string, fallbackHtml: string, keyboard?: InlineKeyboard): Promise<number>;
|
|
18
19
|
editPlain(scopeId: string, messageId: number, text: string, keyboard?: InlineKeyboard): Promise<void>;
|
|
19
20
|
editHtml(scopeId: string, messageId: number, text: string, keyboard?: InlineKeyboard): Promise<void>;
|
|
21
|
+
editRichHtml(scopeId: string, messageId: number, html: string, fallbackHtml: string, keyboard?: InlineKeyboard): Promise<void>;
|
|
20
22
|
deleteMessage(scopeId: string, messageId: number): Promise<void>;
|
|
21
23
|
sendTypingInScope(scopeId: string): Promise<void>;
|
|
22
24
|
clearInlineKeyboard(scopeId: string, messageId: number): Promise<void>;
|
|
@@ -37,6 +37,12 @@ export class BridgeMessagingRouter {
|
|
|
37
37
|
}
|
|
38
38
|
return this.telegram.sendHtml(scopeId, text, keyboard);
|
|
39
39
|
}
|
|
40
|
+
sendRichHtml(scopeId, html, fallbackHtml, keyboard) {
|
|
41
|
+
if (this.isWeixinScope(scopeId)) {
|
|
42
|
+
return this.requireWeixinTransport(scopeId).sendHtml(scopeId, fallbackHtml, keyboard);
|
|
43
|
+
}
|
|
44
|
+
return this.telegram.sendRichHtml(scopeId, html, keyboard);
|
|
45
|
+
}
|
|
40
46
|
editPlain(scopeId, messageId, text, keyboard) {
|
|
41
47
|
if (this.isWeixinScope(scopeId)) {
|
|
42
48
|
return this.requireWeixinTransport(scopeId).editPlain(scopeId, messageId, text, keyboard);
|
|
@@ -49,6 +55,12 @@ export class BridgeMessagingRouter {
|
|
|
49
55
|
}
|
|
50
56
|
return this.telegram.editHtml(scopeId, messageId, text, keyboard);
|
|
51
57
|
}
|
|
58
|
+
editRichHtml(scopeId, messageId, html, fallbackHtml, keyboard) {
|
|
59
|
+
if (this.isWeixinScope(scopeId)) {
|
|
60
|
+
return this.requireWeixinTransport(scopeId).editHtml(scopeId, messageId, fallbackHtml, keyboard);
|
|
61
|
+
}
|
|
62
|
+
return this.telegram.editRichHtml(scopeId, messageId, html, keyboard);
|
|
63
|
+
}
|
|
52
64
|
deleteMessage(scopeId, messageId) {
|
|
53
65
|
if (this.isWeixinScope(scopeId)) {
|
|
54
66
|
return this.requireWeixinTransport(scopeId).deleteMessage(scopeId, messageId);
|
|
@@ -13,8 +13,10 @@ export declare class TelegramMessagingPort implements ChannelPort {
|
|
|
13
13
|
constructor(gateway: TelegramGateway);
|
|
14
14
|
sendPlain(bridgeScopeId: string, text: string, inlineKeyboard?: InlineKeyboard): Promise<number>;
|
|
15
15
|
sendHtml(bridgeScopeId: string, text: string, inlineKeyboard?: InlineKeyboard): Promise<number>;
|
|
16
|
+
sendRichHtml(bridgeScopeId: string, html: string, inlineKeyboard?: InlineKeyboard): Promise<number>;
|
|
16
17
|
editPlain(bridgeScopeId: string, messageId: number, text: string, inlineKeyboard?: InlineKeyboard): Promise<void>;
|
|
17
18
|
editHtml(bridgeScopeId: string, messageId: number, text: string, inlineKeyboard?: InlineKeyboard): Promise<void>;
|
|
19
|
+
editRichHtml(bridgeScopeId: string, messageId: number, html: string, inlineKeyboard?: InlineKeyboard): Promise<void>;
|
|
18
20
|
deleteMessage(bridgeScopeId: string, messageId: number): Promise<void>;
|
|
19
21
|
sendTypingInScope(bridgeScopeId: string): Promise<void>;
|
|
20
22
|
clearInlineKeyboard(bridgeScopeId: string, messageId: number): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseTelegramTargetFromBridgeScope } from '../../core/bridge_scope.js';
|
|
2
|
+
import { telegramRichHtml } from '../../telegram/rich.js';
|
|
2
3
|
/**
|
|
3
4
|
* Telegram outbound operations addressed by bridge scope id (`telegram:…`).
|
|
4
5
|
*/
|
|
@@ -15,6 +16,10 @@ export class TelegramMessagingPort {
|
|
|
15
16
|
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
16
17
|
return this.gateway.sendHtmlMessage(target.chatId, text, inlineKeyboard, target.topicId);
|
|
17
18
|
}
|
|
19
|
+
async sendRichHtml(bridgeScopeId, html, inlineKeyboard) {
|
|
20
|
+
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
21
|
+
return this.gateway.sendRichMessage(target.chatId, telegramRichHtml(html, { skipEntityDetection: true }), inlineKeyboard, target.topicId);
|
|
22
|
+
}
|
|
18
23
|
async editPlain(bridgeScopeId, messageId, text, inlineKeyboard) {
|
|
19
24
|
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
20
25
|
await this.gateway.editMessage(target.chatId, messageId, text, inlineKeyboard);
|
|
@@ -23,6 +28,10 @@ export class TelegramMessagingPort {
|
|
|
23
28
|
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
24
29
|
await this.gateway.editHtmlMessage(target.chatId, messageId, text, inlineKeyboard);
|
|
25
30
|
}
|
|
31
|
+
async editRichHtml(bridgeScopeId, messageId, html, inlineKeyboard) {
|
|
32
|
+
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
33
|
+
await this.gateway.editRichMessage(target.chatId, messageId, telegramRichHtml(html, { skipEntityDetection: true }), inlineKeyboard);
|
|
34
|
+
}
|
|
26
35
|
async deleteMessage(bridgeScopeId, messageId) {
|
|
27
36
|
const target = parseTelegramTargetFromBridgeScope(bridgeScopeId);
|
|
28
37
|
await this.gateway.deleteMessage(target.chatId, messageId);
|
|
@@ -227,8 +227,10 @@ export declare class BridgeSessionCore {
|
|
|
227
227
|
private updateStatus;
|
|
228
228
|
private sendMessage;
|
|
229
229
|
private sendHtmlMessage;
|
|
230
|
+
private sendRichHtmlMessage;
|
|
230
231
|
private editMessage;
|
|
231
232
|
private editHtmlMessage;
|
|
233
|
+
private editRichHtmlMessage;
|
|
232
234
|
private deleteMessage;
|
|
233
235
|
private sendTyping;
|
|
234
236
|
private sendObservedCliUserMessage;
|
|
@@ -318,6 +320,7 @@ export declare class BridgeSessionCore {
|
|
|
318
320
|
private handleArchiveCommand;
|
|
319
321
|
private handleUnarchiveCommand;
|
|
320
322
|
private handleReviewCommand;
|
|
323
|
+
private handleRichCommand;
|
|
321
324
|
private handleDiffCommand;
|
|
322
325
|
private handleLoadedCommand;
|
|
323
326
|
private handleSkillsCommand;
|
|
@@ -9,6 +9,8 @@ import { buildAccessSettingsKeyboard, buildModelSettingsKeyboard, buildSetupPane
|
|
|
9
9
|
import { clampServiceTierToModel, resolveFastTierForModel } from './service_tier.js';
|
|
10
10
|
import { TELEGRAM_BOT_API_DOWNLOAD_LIMIT_BYTES, buildAttachmentPrompt, isNativeImageAttachment, planAttachmentStoragePath, summarizeTelegramInput, } from '../telegram/media.js';
|
|
11
11
|
import { TELEGRAM_MESSAGE_LIMIT, chunkTelegramMessage, chunkTelegramStreamMessage, clipTelegramDraftMessage, } from '../telegram/text.js';
|
|
12
|
+
import { escapeTelegramHtml, telegramBold, telegramDetails, telegramExpandableBlockquote, telegramPre, telegramPreCode, } from '../telegram/html.js';
|
|
13
|
+
import { TELEGRAM_RICH_MESSAGE_TEXT_LIMIT } from '../telegram/rich.js';
|
|
12
14
|
import { isDefaultTelegramScope, resolveTelegramAddressing } from '../telegram/addressing.js';
|
|
13
15
|
import { BRIDGE_SCOPE_WEIXIN_PREFIX, parseTelegramTargetFromBridgeScope, parseWeixinBridgeScope } from '../core/bridge_scope.js';
|
|
14
16
|
import { resolveTelegramRenderRoute } from '../telegram/rendering.js';
|
|
@@ -50,6 +52,7 @@ const PINNED_HELP_COMMANDS = [
|
|
|
50
52
|
const DYNAMIC_HELP_COMMANDS = [
|
|
51
53
|
{ key: 'fast', line: '/fast <on|off|toggle>' },
|
|
52
54
|
{ key: 'active', line: '/active <steer|queue>' },
|
|
55
|
+
{ key: 'rich', line: '/rich' },
|
|
53
56
|
{ key: 'account', line: '/account' },
|
|
54
57
|
{ key: 'quota', line: '/quota' },
|
|
55
58
|
{ key: 'update', line: '/update' },
|
|
@@ -717,6 +720,10 @@ export class BridgeSessionCore {
|
|
|
717
720
|
await this.handleReviewCommand(event, locale, args);
|
|
718
721
|
return;
|
|
719
722
|
}
|
|
723
|
+
case 'rich': {
|
|
724
|
+
await this.handleRichCommand(scopeId, locale);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
720
727
|
case 'diff': {
|
|
721
728
|
await this.handleDiffCommand(scopeId, locale);
|
|
722
729
|
return;
|
|
@@ -3356,12 +3363,30 @@ export class BridgeSessionCore {
|
|
|
3356
3363
|
async sendHtmlMessage(scopeId, text, inlineKeyboard) {
|
|
3357
3364
|
return this.messaging.sendHtml(scopeId, text, inlineKeyboard);
|
|
3358
3365
|
}
|
|
3366
|
+
async sendRichHtmlMessage(scopeId, html, fallbackHtml, inlineKeyboard) {
|
|
3367
|
+
try {
|
|
3368
|
+
return await this.messaging.sendRichHtml(scopeId, html, fallbackHtml, inlineKeyboard);
|
|
3369
|
+
}
|
|
3370
|
+
catch (error) {
|
|
3371
|
+
this.logger.warn('telegram.rich_message_send_failed', { scopeId, error: toErrorMeta(error) });
|
|
3372
|
+
return this.sendHtmlMessage(scopeId, fallbackHtml, inlineKeyboard);
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3359
3375
|
async editMessage(scopeId, messageId, text, inlineKeyboard) {
|
|
3360
3376
|
await this.messaging.editPlain(scopeId, messageId, text, inlineKeyboard);
|
|
3361
3377
|
}
|
|
3362
3378
|
async editHtmlMessage(scopeId, messageId, text, inlineKeyboard) {
|
|
3363
3379
|
await this.messaging.editHtml(scopeId, messageId, text, inlineKeyboard);
|
|
3364
3380
|
}
|
|
3381
|
+
async editRichHtmlMessage(scopeId, messageId, html, fallbackHtml, inlineKeyboard) {
|
|
3382
|
+
try {
|
|
3383
|
+
await this.messaging.editRichHtml(scopeId, messageId, html, fallbackHtml, inlineKeyboard);
|
|
3384
|
+
}
|
|
3385
|
+
catch (error) {
|
|
3386
|
+
this.logger.warn('telegram.rich_message_edit_failed', { scopeId, messageId, error: toErrorMeta(error) });
|
|
3387
|
+
await this.editHtmlMessage(scopeId, messageId, fallbackHtml, inlineKeyboard);
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3365
3390
|
async deleteMessage(scopeId, messageId) {
|
|
3366
3391
|
await this.messaging.deleteMessage(scopeId, messageId);
|
|
3367
3392
|
}
|
|
@@ -3373,8 +3398,8 @@ export class BridgeSessionCore {
|
|
|
3373
3398
|
for (let index = 0; index < chunks.length; index += 1) {
|
|
3374
3399
|
const chunk = chunks[index];
|
|
3375
3400
|
const body = index === 0
|
|
3376
|
-
?
|
|
3377
|
-
:
|
|
3401
|
+
? `${telegramBold(OBSERVED_CLI_USER_LABEL)}\n${telegramPre(chunk)}`
|
|
3402
|
+
: telegramPre(chunk);
|
|
3378
3403
|
await this.sendHtmlMessage(scopeId, body);
|
|
3379
3404
|
}
|
|
3380
3405
|
}
|
|
@@ -5052,13 +5077,16 @@ export class BridgeSessionCore {
|
|
|
5052
5077
|
await this.registerActiveTurn(event.scopeId, event.chatId, event.chatType, event.topicId, result.reviewThreadId, result.turnId, 0);
|
|
5053
5078
|
}
|
|
5054
5079
|
}
|
|
5080
|
+
async handleRichCommand(scopeId, locale) {
|
|
5081
|
+
await this.sendRichHtmlMessage(scopeId, formatRichDemoMessage(locale), formatRichDemoFallbackMessage(locale));
|
|
5082
|
+
}
|
|
5055
5083
|
async handleDiffCommand(scopeId, locale) {
|
|
5056
5084
|
const diff = this.latestTurnDiffs.get(scopeId);
|
|
5057
5085
|
if (!diff?.diff.trim()) {
|
|
5058
5086
|
await this.sendMessage(scopeId, t(locale, 'diff_unavailable'));
|
|
5059
5087
|
return;
|
|
5060
5088
|
}
|
|
5061
|
-
await this.
|
|
5089
|
+
await this.sendRichHtmlMessage(scopeId, formatRichDiffMessage(locale, diff.diff), formatDiffMessage(locale, diff.diff));
|
|
5062
5090
|
}
|
|
5063
5091
|
async handleLoadedCommand(scopeId, locale) {
|
|
5064
5092
|
const threadIds = await this.app.listLoadedThreads();
|
|
@@ -7990,10 +8018,9 @@ function renderArchivedToolBatchStatus(locale, counts, actionLines) {
|
|
|
7990
8018
|
return { text, html: null };
|
|
7991
8019
|
}
|
|
7992
8020
|
const heading = formatToolBatchHeading(locale, counts, false);
|
|
7993
|
-
const detailLines = actionLines.slice(0, 12).map(line => escapeTelegramHtml(line));
|
|
7994
8021
|
const html = [
|
|
7995
|
-
|
|
7996
|
-
|
|
8022
|
+
telegramBold(heading),
|
|
8023
|
+
telegramExpandableBlockquote(actionLines.slice(0, 12).join('\n')),
|
|
7997
8024
|
].join('\n');
|
|
7998
8025
|
return { text, html };
|
|
7999
8026
|
}
|
|
@@ -8142,12 +8169,6 @@ function truncateInline(value, limit) {
|
|
|
8142
8169
|
}
|
|
8143
8170
|
return `${value.slice(0, Math.max(0, limit - 1))}…`;
|
|
8144
8171
|
}
|
|
8145
|
-
function escapeTelegramHtml(value) {
|
|
8146
|
-
return value
|
|
8147
|
-
.replaceAll('&', '&')
|
|
8148
|
-
.replaceAll('<', '<')
|
|
8149
|
-
.replaceAll('>', '>');
|
|
8150
|
-
}
|
|
8151
8172
|
function parseReviewTarget(args) {
|
|
8152
8173
|
if (args.length === 0) {
|
|
8153
8174
|
return { type: 'uncommittedChanges' };
|
|
@@ -8260,7 +8281,97 @@ function formatMcpResourceMessage(locale, server, uri, contents) {
|
|
|
8260
8281
|
}
|
|
8261
8282
|
function formatDiffMessage(locale, diff) {
|
|
8262
8283
|
const clipped = diff.length > 3500 ? `${diff.slice(0, 3500)}\n...` : diff;
|
|
8263
|
-
return
|
|
8284
|
+
return [
|
|
8285
|
+
telegramBold(t(locale, 'diff_title')),
|
|
8286
|
+
telegramExpandableBlockquote(clipped),
|
|
8287
|
+
].join('\n');
|
|
8288
|
+
}
|
|
8289
|
+
function formatRichDiffMessage(locale, diff) {
|
|
8290
|
+
const clipped = clipRichMessageText(diff, Math.min(24_000, TELEGRAM_RICH_MESSAGE_TEXT_LIMIT - 1024));
|
|
8291
|
+
const summary = locale === 'zh' ? '展开 diff' : 'Expand diff';
|
|
8292
|
+
const footer = locale === 'zh'
|
|
8293
|
+
? 'FoxClaw · sendRichMessage · details/pre/code'
|
|
8294
|
+
: 'FoxClaw · sendRichMessage · details/pre/code';
|
|
8295
|
+
return [
|
|
8296
|
+
`<h3>${escapeTelegramHtml(t(locale, 'diff_title'))}</h3>`,
|
|
8297
|
+
telegramDetails(summary, telegramPreCode(clipped, 'diff')),
|
|
8298
|
+
`<footer>${escapeTelegramHtml(footer)}</footer>`,
|
|
8299
|
+
].join('\n');
|
|
8300
|
+
}
|
|
8301
|
+
function formatRichDemoMessage(locale) {
|
|
8302
|
+
const title = 'FoxClaw RichMessage';
|
|
8303
|
+
const intro = locale === 'zh'
|
|
8304
|
+
? '这条消息通过 Telegram Bot API sendRichMessage 发送,用来验证 Rich Message 在真实客户端里的渲染。'
|
|
8305
|
+
: 'This message is sent through Telegram Bot API sendRichMessage to verify Rich Message rendering in a real client.';
|
|
8306
|
+
const detailsSummary = locale === 'zh' ? '展开 details + pre 示例' : 'Open details + pre sample';
|
|
8307
|
+
const diffSample = [
|
|
8308
|
+
'diff --git a/src/telegram/rich.ts b/src/telegram/rich.ts',
|
|
8309
|
+
'+ sendRichMessage({ rich_message: { html } })',
|
|
8310
|
+
'+ <details><summary>Expandable</summary>...</details>',
|
|
8311
|
+
'+ <table bordered striped>...</table>',
|
|
8312
|
+
].join('\n');
|
|
8313
|
+
const tableCaption = locale === 'zh' ? 'FoxClaw 可用 rich 面' : 'FoxClaw rich surfaces';
|
|
8314
|
+
const surfaceHeader = locale === 'zh' ? '功能面' : 'Surface';
|
|
8315
|
+
const richHeader = locale === 'zh' ? 'Rich 用法' : 'Rich usage';
|
|
8316
|
+
const tableRows = locale === 'zh'
|
|
8317
|
+
? [
|
|
8318
|
+
['`/diff`', 'details + pre/code'],
|
|
8319
|
+
['工具状态', 'details/list'],
|
|
8320
|
+
['`/status`', 'table'],
|
|
8321
|
+
]
|
|
8322
|
+
: [
|
|
8323
|
+
['`/diff`', 'details + pre/code'],
|
|
8324
|
+
['Tool status', 'details/list'],
|
|
8325
|
+
['`/status`', 'table'],
|
|
8326
|
+
];
|
|
8327
|
+
const listItems = locale === 'zh'
|
|
8328
|
+
? ['Gateway 已接入 sendRichMessage', '/diff 已优先使用 RichMessage', '失败会回退到 Telegram HTML']
|
|
8329
|
+
: ['Gateway now supports sendRichMessage', '/diff prefers RichMessage', 'Failures fall back to Telegram HTML'];
|
|
8330
|
+
const detailBody = [
|
|
8331
|
+
`<p>${escapeTelegramHtml(locale === 'zh' ? '下面是 rich pre/code block,客户端支持时会按代码块渲染。' : 'This is a rich pre/code block rendered as code by supported clients.')}</p>`,
|
|
8332
|
+
telegramPreCode(diffSample, 'diff'),
|
|
8333
|
+
].join('\n');
|
|
8334
|
+
return [
|
|
8335
|
+
`<h2>${escapeTelegramHtml(title)}</h2>`,
|
|
8336
|
+
`<p><b>Bot API 10.1</b> ${escapeTelegramHtml(intro)}</p>`,
|
|
8337
|
+
'<hr/>',
|
|
8338
|
+
'<table bordered striped>',
|
|
8339
|
+
`<caption>${escapeTelegramHtml(tableCaption)}</caption>`,
|
|
8340
|
+
`<tr><th>${escapeTelegramHtml(surfaceHeader)}</th><th>${escapeTelegramHtml(richHeader)}</th></tr>`,
|
|
8341
|
+
...tableRows.map(([surface, usage]) => `<tr><td>${escapeTelegramHtml(surface)}</td><td>${escapeTelegramHtml(usage)}</td></tr>`),
|
|
8342
|
+
'</table>',
|
|
8343
|
+
telegramDetails(detailsSummary, detailBody, true),
|
|
8344
|
+
'<ul>',
|
|
8345
|
+
...listItems.map(item => `<li>${escapeTelegramHtml(item)}</li>`),
|
|
8346
|
+
'</ul>',
|
|
8347
|
+
'<footer>FoxClaw · sendRichMessage</footer>',
|
|
8348
|
+
].join('\n');
|
|
8349
|
+
}
|
|
8350
|
+
function formatRichDemoFallbackMessage(locale) {
|
|
8351
|
+
const lines = locale === 'zh'
|
|
8352
|
+
? [
|
|
8353
|
+
'RichMessage fallback 预览',
|
|
8354
|
+
'Gateway 已接入 sendRichMessage',
|
|
8355
|
+
'/diff 已优先使用 RichMessage',
|
|
8356
|
+
'如果你看到这条 HTML fallback,说明 Telegram rich API 返回了失败,正常功能仍可用。',
|
|
8357
|
+
]
|
|
8358
|
+
: [
|
|
8359
|
+
'RichMessage fallback preview',
|
|
8360
|
+
'Gateway now supports sendRichMessage',
|
|
8361
|
+
'/diff prefers RichMessage',
|
|
8362
|
+
'If you see this HTML fallback, Telegram rich API failed but normal messaging still works.',
|
|
8363
|
+
];
|
|
8364
|
+
return [
|
|
8365
|
+
telegramBold('FoxClaw RichMessage'),
|
|
8366
|
+
telegramExpandableBlockquote(lines.join('\n')),
|
|
8367
|
+
telegramPreCode('sendRichMessage({ rich_message: { html } })', 'typescript'),
|
|
8368
|
+
].join('\n');
|
|
8369
|
+
}
|
|
8370
|
+
function clipRichMessageText(value, limit) {
|
|
8371
|
+
if (value.length <= limit) {
|
|
8372
|
+
return value;
|
|
8373
|
+
}
|
|
8374
|
+
return `${value.slice(0, Math.max(0, limit - 4))}\n...`;
|
|
8264
8375
|
}
|
|
8265
8376
|
function formatLoadedThreadsMessage(locale, threadIds) {
|
|
8266
8377
|
const lines = [t(locale, 'loaded_title')];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { t } from '../i18n.js';
|
|
3
|
+
import { escapeTelegramHtml } from '../telegram/html.js';
|
|
3
4
|
import { resolveFastTierForModel } from './service_tier.js';
|
|
4
5
|
export function formatThreadsMessage(locale, threads, currentThreadId, searchTerm, listState) {
|
|
5
6
|
if (threads.length === 0) {
|
|
@@ -642,12 +643,6 @@ function formatIsoTime(locale, unixSeconds) {
|
|
|
642
643
|
return t(locale, 'unknown');
|
|
643
644
|
return new Date(unixSeconds * 1000).toISOString();
|
|
644
645
|
}
|
|
645
|
-
function escapeTelegramHtml(value) {
|
|
646
|
-
return value
|
|
647
|
-
.replaceAll('&', '&')
|
|
648
|
-
.replaceAll('<', '<')
|
|
649
|
-
.replaceAll('>', '>');
|
|
650
|
-
}
|
|
651
646
|
function chunkButtons(buttons, width) {
|
|
652
647
|
const rows = [];
|
|
653
648
|
for (let index = 0; index < buttons.length; index += width) {
|
package/dist/i18n.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ declare const MESSAGES: {
|
|
|
45
45
|
readonly cmd_desc_setup: "Unified preference panel";
|
|
46
46
|
readonly cmd_desc_fast: "Toggle Fast mode";
|
|
47
47
|
readonly cmd_desc_active: "Active-turn message behavior";
|
|
48
|
+
readonly cmd_desc_rich: "Telegram RichMessage demo";
|
|
48
49
|
readonly cmd_desc_status: "Bridge status";
|
|
49
50
|
readonly cmd_desc_update: "Update and restart FoxClaw";
|
|
50
51
|
readonly cmd_desc_account: "Codex account";
|
|
@@ -742,6 +743,7 @@ declare const MESSAGES: {
|
|
|
742
743
|
readonly cmd_desc_setup: "统一偏好面板";
|
|
743
744
|
readonly cmd_desc_fast: "切换 Fast 模式";
|
|
744
745
|
readonly cmd_desc_active: "运行中新消息处理方式";
|
|
746
|
+
readonly cmd_desc_rich: "Telegram RichMessage 演示";
|
|
745
747
|
readonly cmd_desc_status: "查看桥接状态";
|
|
746
748
|
readonly cmd_desc_update: "升级并重启 FoxClaw";
|
|
747
749
|
readonly cmd_desc_account: "Codex 账号";
|
package/dist/i18n.js
CHANGED
|
@@ -43,6 +43,7 @@ const MESSAGES = {
|
|
|
43
43
|
cmd_desc_setup: 'Unified preference panel',
|
|
44
44
|
cmd_desc_fast: 'Toggle Fast mode',
|
|
45
45
|
cmd_desc_active: 'Active-turn message behavior',
|
|
46
|
+
cmd_desc_rich: 'Telegram RichMessage demo',
|
|
46
47
|
cmd_desc_status: 'Bridge status',
|
|
47
48
|
cmd_desc_update: 'Update and restart FoxClaw',
|
|
48
49
|
cmd_desc_account: 'Codex account',
|
|
@@ -740,6 +741,7 @@ const MESSAGES = {
|
|
|
740
741
|
cmd_desc_setup: '统一偏好面板',
|
|
741
742
|
cmd_desc_fast: '切换 Fast 模式',
|
|
742
743
|
cmd_desc_active: '运行中新消息处理方式',
|
|
744
|
+
cmd_desc_rich: 'Telegram RichMessage 演示',
|
|
743
745
|
cmd_desc_status: '查看桥接状态',
|
|
744
746
|
cmd_desc_update: '升级并重启 FoxClaw',
|
|
745
747
|
cmd_desc_account: 'Codex 账号',
|
|
@@ -1412,6 +1414,7 @@ export function getTelegramCommands(locale) {
|
|
|
1412
1414
|
{ command: 'auth', description: t(locale, 'cmd_desc_auth') },
|
|
1413
1415
|
{ command: 'fast', description: t(locale, 'cmd_desc_fast') },
|
|
1414
1416
|
{ command: 'active', description: t(locale, 'cmd_desc_active') },
|
|
1417
|
+
{ command: 'rich', description: t(locale, 'cmd_desc_rich') },
|
|
1415
1418
|
{ command: 'account', description: t(locale, 'cmd_desc_account') },
|
|
1416
1419
|
{ command: 'quota', description: t(locale, 'cmd_desc_quota') },
|
|
1417
1420
|
{ command: 'login_device', description: t(locale, 'cmd_desc_login_device') },
|
|
@@ -4,6 +4,7 @@ import type { BridgeStore } from '../store/database.js';
|
|
|
4
4
|
import type { Logger } from '../logger.js';
|
|
5
5
|
import type { TelegramMessageEntity } from './addressing.js';
|
|
6
6
|
import type { TelegramInboundAttachment } from './media.js';
|
|
7
|
+
import type { TelegramInputRichMessage } from './rich.js';
|
|
7
8
|
export interface TelegramTextEvent {
|
|
8
9
|
chatId: string;
|
|
9
10
|
topicId: number | null;
|
|
@@ -62,8 +63,13 @@ export declare class TelegramGateway extends EventEmitter {
|
|
|
62
63
|
text: string;
|
|
63
64
|
callback_data: string;
|
|
64
65
|
}>>, messageThreadId?: number | null): Promise<number>;
|
|
66
|
+
sendRichMessage(chatId: string, richMessage: TelegramInputRichMessage, inlineKeyboard?: Array<Array<{
|
|
67
|
+
text: string;
|
|
68
|
+
callback_data: string;
|
|
69
|
+
}>>, messageThreadId?: number | null): Promise<number>;
|
|
65
70
|
sendDocument(chatId: string, filename: string, contents: Buffer, caption?: string): Promise<number>;
|
|
66
71
|
sendMessageDraft(chatId: string, draftId: number, text: string, messageThreadId?: number | null): Promise<void>;
|
|
72
|
+
sendRichMessageDraft(chatId: string, draftId: number, richMessage: TelegramInputRichMessage, messageThreadId?: number | null): Promise<void>;
|
|
67
73
|
editMessage(chatId: string, messageId: number, text: string, inlineKeyboard?: Array<Array<{
|
|
68
74
|
text: string;
|
|
69
75
|
callback_data: string;
|
|
@@ -72,6 +78,10 @@ export declare class TelegramGateway extends EventEmitter {
|
|
|
72
78
|
text: string;
|
|
73
79
|
callback_data: string;
|
|
74
80
|
}>>): Promise<void>;
|
|
81
|
+
editRichMessage(chatId: string, messageId: number, richMessage: TelegramInputRichMessage, inlineKeyboard?: Array<Array<{
|
|
82
|
+
text: string;
|
|
83
|
+
callback_data: string;
|
|
84
|
+
}>>): Promise<void>;
|
|
75
85
|
clearMessageInlineKeyboard(chatId: string, messageId: number): Promise<void>;
|
|
76
86
|
private sendMessageWithOptions;
|
|
77
87
|
private editMessageWithOptions;
|
package/dist/telegram/gateway.js
CHANGED
|
@@ -56,6 +56,18 @@ export class TelegramGateway extends EventEmitter {
|
|
|
56
56
|
async sendHtmlMessage(chatId, text, inlineKeyboard, messageThreadId) {
|
|
57
57
|
return this.sendMessageWithOptions(chatId, text, inlineKeyboard, 'HTML', messageThreadId);
|
|
58
58
|
}
|
|
59
|
+
async sendRichMessage(chatId, richMessage, inlineKeyboard, messageThreadId) {
|
|
60
|
+
const result = await callTelegramApi(this.botToken, 'sendRichMessage', {
|
|
61
|
+
chat_id: chatId,
|
|
62
|
+
rich_message: richMessage,
|
|
63
|
+
...(messageThreadId !== null && messageThreadId !== undefined ? { message_thread_id: messageThreadId } : {}),
|
|
64
|
+
...(inlineKeyboard ? { reply_markup: { inline_keyboard: inlineKeyboard } } : {}),
|
|
65
|
+
});
|
|
66
|
+
if (!result.ok || !result.result) {
|
|
67
|
+
throw new Error(result.description || 'Failed to send Telegram rich message');
|
|
68
|
+
}
|
|
69
|
+
return result.result.message_id;
|
|
70
|
+
}
|
|
59
71
|
async sendDocument(chatId, filename, contents, caption) {
|
|
60
72
|
const result = await callTelegramMultipartApi(this.botToken, 'sendDocument', {
|
|
61
73
|
chat_id: chatId,
|
|
@@ -83,12 +95,34 @@ export class TelegramGateway extends EventEmitter {
|
|
|
83
95
|
throw new Error(result.description || 'Failed to send Telegram draft message');
|
|
84
96
|
}
|
|
85
97
|
}
|
|
98
|
+
async sendRichMessageDraft(chatId, draftId, richMessage, messageThreadId) {
|
|
99
|
+
const result = await callTelegramApi(this.botToken, 'sendRichMessageDraft', {
|
|
100
|
+
chat_id: chatId,
|
|
101
|
+
draft_id: draftId,
|
|
102
|
+
rich_message: richMessage,
|
|
103
|
+
...(messageThreadId !== null && messageThreadId !== undefined ? { message_thread_id: messageThreadId } : {}),
|
|
104
|
+
});
|
|
105
|
+
if (!result.ok) {
|
|
106
|
+
throw new Error(result.description || 'Failed to send Telegram rich draft message');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
86
109
|
async editMessage(chatId, messageId, text, inlineKeyboard) {
|
|
87
110
|
return this.editMessageWithOptions(chatId, messageId, text, inlineKeyboard);
|
|
88
111
|
}
|
|
89
112
|
async editHtmlMessage(chatId, messageId, text, inlineKeyboard) {
|
|
90
113
|
return this.editMessageWithOptions(chatId, messageId, text, inlineKeyboard, 'HTML');
|
|
91
114
|
}
|
|
115
|
+
async editRichMessage(chatId, messageId, richMessage, inlineKeyboard) {
|
|
116
|
+
const result = await callTelegramApi(this.botToken, 'editMessageText', {
|
|
117
|
+
chat_id: chatId,
|
|
118
|
+
message_id: messageId,
|
|
119
|
+
rich_message: richMessage,
|
|
120
|
+
...(inlineKeyboard ? { reply_markup: { inline_keyboard: inlineKeyboard } } : {}),
|
|
121
|
+
});
|
|
122
|
+
if (!result.ok && !String(result.description || '').includes('message is not modified')) {
|
|
123
|
+
throw new Error(result.description || 'Failed to edit Telegram rich message');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
92
126
|
async clearMessageInlineKeyboard(chatId, messageId) {
|
|
93
127
|
const result = await callTelegramApi(this.botToken, 'editMessageReplyMarkup', {
|
|
94
128
|
chat_id: chatId,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function escapeTelegramHtml(value: string): string;
|
|
2
|
+
export declare function telegramBold(value: string): string;
|
|
3
|
+
export declare function telegramCode(value: string): string;
|
|
4
|
+
export declare function telegramPre(value: string): string;
|
|
5
|
+
export declare function telegramPreCode(value: string, language?: string): string;
|
|
6
|
+
export declare function telegramExpandableBlockquote(value: string): string;
|
|
7
|
+
export declare function telegramSpoiler(value: string): string;
|
|
8
|
+
export declare function telegramDetails(summary: string, bodyHtml: string, open?: boolean): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function escapeTelegramHtml(value) {
|
|
2
|
+
return value
|
|
3
|
+
.replaceAll('&', '&')
|
|
4
|
+
.replaceAll('<', '<')
|
|
5
|
+
.replaceAll('>', '>');
|
|
6
|
+
}
|
|
7
|
+
function escapeTelegramHtmlAttribute(value) {
|
|
8
|
+
return escapeTelegramHtml(value).replaceAll('"', '"');
|
|
9
|
+
}
|
|
10
|
+
export function telegramBold(value) {
|
|
11
|
+
return `<b>${escapeTelegramHtml(value)}</b>`;
|
|
12
|
+
}
|
|
13
|
+
export function telegramCode(value) {
|
|
14
|
+
return `<code>${escapeTelegramHtml(value)}</code>`;
|
|
15
|
+
}
|
|
16
|
+
export function telegramPre(value) {
|
|
17
|
+
return `<pre>${escapeTelegramHtml(value)}</pre>`;
|
|
18
|
+
}
|
|
19
|
+
export function telegramPreCode(value, language) {
|
|
20
|
+
const classAttr = language ? ` class="language-${escapeTelegramHtmlAttribute(language)}"` : '';
|
|
21
|
+
return `<pre><code${classAttr}>${escapeTelegramHtml(value)}</code></pre>`;
|
|
22
|
+
}
|
|
23
|
+
export function telegramExpandableBlockquote(value) {
|
|
24
|
+
return `<blockquote expandable>${escapeTelegramHtml(value)}</blockquote>`;
|
|
25
|
+
}
|
|
26
|
+
export function telegramSpoiler(value) {
|
|
27
|
+
return `<tg-spoiler>${escapeTelegramHtml(value)}</tg-spoiler>`;
|
|
28
|
+
}
|
|
29
|
+
export function telegramDetails(summary, bodyHtml, open = false) {
|
|
30
|
+
return `<details${open ? ' open' : ''}><summary>${escapeTelegramHtml(summary)}</summary>${bodyHtml}</details>`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const TELEGRAM_RICH_MESSAGE_TEXT_LIMIT = 32768;
|
|
2
|
+
export declare const TELEGRAM_RICH_MESSAGE_BLOCK_LIMIT = 500;
|
|
3
|
+
export interface TelegramInputRichMessage {
|
|
4
|
+
html?: string;
|
|
5
|
+
markdown?: string;
|
|
6
|
+
is_rtl?: true;
|
|
7
|
+
skip_entity_detection?: true;
|
|
8
|
+
}
|
|
9
|
+
export interface TelegramRichMessageOptions {
|
|
10
|
+
isRtl?: boolean;
|
|
11
|
+
skipEntityDetection?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function telegramRichHtml(html: string, options?: TelegramRichMessageOptions): TelegramInputRichMessage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const TELEGRAM_RICH_MESSAGE_TEXT_LIMIT = 32_768;
|
|
2
|
+
export const TELEGRAM_RICH_MESSAGE_BLOCK_LIMIT = 500;
|
|
3
|
+
export function telegramRichHtml(html, options = {}) {
|
|
4
|
+
const message = { html };
|
|
5
|
+
if (options.isRtl) {
|
|
6
|
+
message.is_rtl = true;
|
|
7
|
+
}
|
|
8
|
+
if (options.skipEntityDetection) {
|
|
9
|
+
message.skip_entity_detection = true;
|
|
10
|
+
}
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Telegram Rich Message Adaptation Check
|
|
2
|
+
|
|
3
|
+
Checked on 2026-06-16 against Telegram Bot API Rich Messages, especially `RichMessage`, `sendRichMessage`, `sendRichMessageDraft`, and Rich Message Formatting Options.
|
|
4
|
+
|
|
5
|
+
Official references:
|
|
6
|
+
|
|
7
|
+
- https://core.telegram.org/bots/api#rich-message-formatting-options
|
|
8
|
+
- https://core.telegram.org/bots/api#sendrichmessage
|
|
9
|
+
- https://core.telegram.org/bots/api#sendrichmessagedraft
|
|
10
|
+
|
|
11
|
+
## Conclusion
|
|
12
|
+
|
|
13
|
+
FoxClaw can benefit from the new rich message surface, and RichMessage is now wired into Telegram surfaces that are easy to inspect and safe to fall back.
|
|
14
|
+
|
|
15
|
+
The current strategy is to try `sendRichMessage` first on Telegram, then fall back to the existing Telegram HTML path on failure. Weixin continues to use HTML/plain fallback. Bot API 10.1 Rich Messages start with diagnostics and structured long text, then can expand to status, auth/quota, and AI draft streaming.
|
|
16
|
+
|
|
17
|
+
Already landed in this pass:
|
|
18
|
+
|
|
19
|
+
- Added `src/telegram/html.ts` for centralized Telegram HTML escaping and tag helpers.
|
|
20
|
+
- Added `src/telegram/rich.ts` and wired `sendRichMessage` / rich HTML through `TelegramGateway`, `TelegramMessagingPort`, and `BridgeMessagingRouter`.
|
|
21
|
+
- Added `/rich` as a diagnostic command for checking heading, table, details, pre/code, and list rendering in a real Telegram client.
|
|
22
|
+
- Changed `/diff` to prefer RichMessage with a heading plus details/pre/code diff block, falling back to HTML bold title plus expandable quote body.
|
|
23
|
+
- Moved existing CLI observation and archived tool-batch HTML generation onto the shared helper.
|
|
24
|
+
|
|
25
|
+
## Official Capability
|
|
26
|
+
|
|
27
|
+
Bot API 10.1 adds Rich Messages:
|
|
28
|
+
|
|
29
|
+
- `RichText*`: bold, italic, underline, strikethrough, spoiler, code, marked, math, URL, email, phone, mention, hashtag, bot command, anchors, and references.
|
|
30
|
+
- `RichBlock*`: paragraph, heading, preformatted, footer, divider, math block, anchor, list, block quote, pull quote, collage, slideshow, table, details, map, media blocks, and thinking.
|
|
31
|
+
- `sendRichMessage`: sends a complete rich message.
|
|
32
|
+
- `sendRichMessageDraft`: streams an ephemeral partial rich message in private chat; the final answer must still be persisted with `sendRichMessage`.
|
|
33
|
+
- `editMessageText` accepts `rich_message` for editing rich messages.
|
|
34
|
+
|
|
35
|
+
Rich Message HTML also supports tags such as `<details>`, `<table>`, `<pre><code class="language-...">`, `<ul>/<ol>`, `<hr/>`, `<tg-math-block>`, and `<tg-thinking>`. `RichBlockThinking` is draft-only.
|
|
36
|
+
|
|
37
|
+
## FoxClaw Inventory
|
|
38
|
+
|
|
39
|
+
Current Telegram send layer:
|
|
40
|
+
|
|
41
|
+
- `src/telegram/gateway.ts`: plain/html/rich send and edit are wired; regular HTML uses `parse_mode=HTML`, while rich messages use `rich_message.html`.
|
|
42
|
+
- `src/channels/telegram/telegram_messaging_port.ts`: controller-facing plain/html/rich-html send/edit and text draft operations.
|
|
43
|
+
- `src/telegram/rendering.ts`: `segmented_stream` is the default; `draft_stream` still uses the old text draft path.
|
|
44
|
+
- `src/controller/controller.ts`: central dispatcher for status cards, approvals, tool batches, diffs, auth, MCP, plugins, files, and runtime summaries.
|
|
45
|
+
- `src/controller/presentation.ts`: `/threads`, `/setup`, model, and access panels already use Telegram HTML.
|
|
46
|
+
|
|
47
|
+
Useful mapping:
|
|
48
|
+
|
|
49
|
+
| Surface | Current state | Useful rich capabilities | Recommendation |
|
|
50
|
+
| --- | --- | --- | --- |
|
|
51
|
+
| Active turn status | Short plain text, frequent edits | heading, list, thinking draft | Keep stable; use `RichBlockThinking` later only for private draft streaming |
|
|
52
|
+
| Codex streaming replies | Segmented plain text | rich draft, paragraph, pre, details | Feature flag only; needs fallback |
|
|
53
|
+
| Archived tool batches | Expandable HTML quote | details, pre, list | Keep HTML now; later use rich details |
|
|
54
|
+
| `/diff` | RichMessage first, HTML fallback | pre language, details | Landed |
|
|
55
|
+
| Approvals | Plain text plus inline keyboard | code, pre, spoiler, details | Command/path/patch fit code/pre/details; sensitive params should be hidden |
|
|
56
|
+
| `/status` and runtime summaries | Plain text lists | table, heading, footer | Good candidate for rich tables |
|
|
57
|
+
| `/auth` and `/quota` | Compact text plus buttons | table, marked, spoiler | Quota windows fit tables; abnormal candidates fit marked text |
|
|
58
|
+
| `/threads` and `/setup` | HTML panels | heading, list, anchor | Current HTML is enough; medium priority |
|
|
59
|
+
| MCP resources and plugin skills | Long plain text | details, pre, anchor/reference | Good candidate for collapsible schema/resource blocks |
|
|
60
|
+
| Help and setup text | Plain text | heading, list, code | Low priority |
|
|
61
|
+
| Media attachment feedback | Plain summary | collage/slideshow/media captions | Use only if FoxClaw starts returning media previews |
|
|
62
|
+
|
|
63
|
+
## Rollout Plan
|
|
64
|
+
|
|
65
|
+
Phase 1: HTML-compatible enhancement.
|
|
66
|
+
|
|
67
|
+
- Centralize Telegram HTML helpers.
|
|
68
|
+
- Collapse long content by default: diffs, tool logs, MCP resources, plugin skill contents.
|
|
69
|
+
- Render commands, paths, models, and candidate names as code.
|
|
70
|
+
- Use spoilers or omission for secret/token-like diagnostics.
|
|
71
|
+
|
|
72
|
+
Phase 2: Rich Message builder.
|
|
73
|
+
|
|
74
|
+
Done:
|
|
75
|
+
|
|
76
|
+
- Added a minimal typed `src/telegram/rich.ts`.
|
|
77
|
+
- Added `sendRichMessage`, `editRichMessage`, and `sendRichMessageDraft` to `TelegramGateway`.
|
|
78
|
+
- Added rich HTML send/edit to `TelegramMessagingPort` and `BridgeMessagingRouter`; Weixin scopes use fallback HTML.
|
|
79
|
+
- `/rich` and `/diff` use rich sending first and fall back to HTML.
|
|
80
|
+
|
|
81
|
+
Next:
|
|
82
|
+
|
|
83
|
+
- Move `/status`, `/auth`, `/quota`, and MCP resources to rich table/details.
|
|
84
|
+
- Decide whether a global config flag is needed after real Telegram client checks.
|
|
85
|
+
|
|
86
|
+
Phase 3: Rich draft streaming.
|
|
87
|
+
|
|
88
|
+
- Enable only in Telegram private chats first; keep group/topic rendering on the current segmented stream.
|
|
89
|
+
- Use `RichBlockThinking` while generating and paragraph/pre/details for partial output.
|
|
90
|
+
- Persist the final answer with `sendRichMessage`.
|
|
91
|
+
- Keep the old text draft and segmented stream as fallback paths.
|
|
92
|
+
|
|
93
|
+
## Risks
|
|
94
|
+
|
|
95
|
+
- Rich Messages landed in Bot API 10.1 on 2026-06-11, so client compatibility should be checked with `/rich` and `/diff`.
|
|
96
|
+
- `sendRichMessageDraft` targets private users; group, topic, and multi-bot paths must keep existing rendering.
|
|
97
|
+
- Rich media blocks add bot permission and media URL/upload constraints; they are not a Phase 1 target.
|
|
98
|
+
- Automatic entity detection can mis-detect paths, emails, URLs, and commands; rich builders should choose `skip_entity_detection` per message type.
|
|
99
|
+
- All Codex, shell, and file output must pass through centralized escaping before entering HTML/rich markup.
|
package/docs/user-manual.md
CHANGED
|
@@ -265,6 +265,10 @@ It controls:
|
|
|
265
265
|
|
|
266
266
|
Telegram renders the HTML and buttons. This text block approximates the real panel:
|
|
267
267
|
|
|
268
|
+
For the Telegram Rich Message inventory and rollout plan, see [Telegram Rich Message Adaptation Check](./telegram-rich-messages.md). The default path still favors Telegram HTML for compatibility.
|
|
269
|
+
|
|
270
|
+
Send `/rich` to view a RichMessage demo in the current Telegram client. `/diff` also prefers RichMessage details plus a diff code block, with automatic Telegram HTML fallback.
|
|
271
|
+
|
|
268
272
|
```text
|
|
269
273
|
Session preferences
|
|
270
274
|
Current: gpt-5.5 · high · fast=off · default · Agent · Steer current turn
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Telegram Rich Message 适配专项检查
|
|
2
|
+
|
|
3
|
+
检查日期:2026-06-16。依据:Telegram Bot API Rich Messages 文档,尤其是 `RichMessage`、`sendRichMessage`、`sendRichMessageDraft` 与 Rich Message Formatting Options。
|
|
4
|
+
|
|
5
|
+
官方入口:
|
|
6
|
+
|
|
7
|
+
- https://core.telegram.org/bots/api#rich-message-formatting-options
|
|
8
|
+
- https://core.telegram.org/bots/api#sendrichmessage
|
|
9
|
+
- https://core.telegram.org/bots/api#sendrichmessagedraft
|
|
10
|
+
|
|
11
|
+
## 结论
|
|
12
|
+
|
|
13
|
+
FoxClaw 有明确收益,并已开始把 RichMessage 用在适合看效果、可安全回退的 Telegram 功能面。
|
|
14
|
+
|
|
15
|
+
现在的策略是:Telegram 优先尝试 `sendRichMessage`,失败时回退到既有 Telegram HTML;微信继续使用 HTML/plain 回退。Bot API 10.1 的 Rich Message 先用于可观察的诊断和结构化长文本,再逐步扩展到状态、auth/quota 和 AI draft streaming。
|
|
16
|
+
|
|
17
|
+
本次已先落地低风险增强:
|
|
18
|
+
|
|
19
|
+
- 新增 `src/telegram/html.ts`,统一 Telegram HTML 转义和常用标签生成。
|
|
20
|
+
- 新增 `src/telegram/rich.ts`,并在 `TelegramGateway` / `TelegramMessagingPort` / `BridgeMessagingRouter` 接入 `sendRichMessage` / rich HTML 发送链路。
|
|
21
|
+
- 新增 `/rich` 诊断命令,用来在真实 Telegram 客户端查看 heading、table、details、pre/code、list 的 RichMessage 效果。
|
|
22
|
+
- `/diff` 改为优先发送 RichMessage:标题用 heading,diff 内容放入 details + pre/code;rich 发送失败时回退到 HTML 加粗标题和可展开引用块。
|
|
23
|
+
- 现有 CLI 观察消息和归档工具批次状态复用同一套 HTML helper。
|
|
24
|
+
|
|
25
|
+
## 官方能力摘录
|
|
26
|
+
|
|
27
|
+
Bot API 10.1 新增 Rich Messages:
|
|
28
|
+
|
|
29
|
+
- `RichText*`:bold、italic、underline、strikethrough、spoiler、code、marked、math、url、email、phone、mention、hashtag、bot command、anchor/reference 等。
|
|
30
|
+
- `RichBlock*`:paragraph、heading、pre、footer、divider、math block、anchor、list、blockquote、pullquote、collage、slideshow、table、details、map、photo/video/audio/animation/voice、thinking。
|
|
31
|
+
- `sendRichMessage`:发送完整 rich message。
|
|
32
|
+
- `sendRichMessageDraft`:在私聊里流式发送临时 rich draft;draft 是短暂预览,最终仍要用 `sendRichMessage` 发送完整消息。
|
|
33
|
+
- `editMessageText` 新增 `rich_message` 参数,可编辑 rich message。
|
|
34
|
+
|
|
35
|
+
Rich Message HTML 还支持 `<details>`、`<table>`、`<pre><code class="language-...">`、`<ul>/<ol>`、`<hr/>`、`<tg-math-block>`、`<tg-thinking>` 等标签。`RichBlockThinking` 只能用于 `sendRichMessageDraft`。
|
|
36
|
+
|
|
37
|
+
## FoxClaw 现状
|
|
38
|
+
|
|
39
|
+
当前 Telegram 发送层:
|
|
40
|
+
|
|
41
|
+
- `src/telegram/gateway.ts`:`sendMessage`、`sendHtmlMessage`、`sendRichMessage`、`editMessage`、`editHtmlMessage`、`editRichMessage` 已接入;HTML 普通消息使用 `parse_mode=HTML`,rich 消息使用 `rich_message.html`。
|
|
42
|
+
- `src/channels/telegram/telegram_messaging_port.ts`:对 controller 暴露 plain/html/rich-html send/edit 和 `sendDraft`。
|
|
43
|
+
- `src/telegram/rendering.ts`:默认 `segmented_stream`;`draft_stream` 仍是旧 `sendMessageDraft` 文本 draft。
|
|
44
|
+
- `src/controller/controller.ts`:状态卡、审批、工具批次、diff、auth、MCP、插件、文件等功能面都在这里汇总发送。
|
|
45
|
+
- `src/controller/presentation.ts`:`/threads`、`/setup`、模型/权限面板已经使用 Telegram HTML。
|
|
46
|
+
|
|
47
|
+
已经使用的格式能力:
|
|
48
|
+
|
|
49
|
+
- `/threads`、`/setup` 等面板:加粗、code、HTML escape。
|
|
50
|
+
- CLI 观察消息:`<pre>`。
|
|
51
|
+
- 归档工具批次状态:`<blockquote expandable>`。
|
|
52
|
+
- 本次增强后的 `/diff`:加粗标题和可展开引用块。
|
|
53
|
+
|
|
54
|
+
已经接入:
|
|
55
|
+
|
|
56
|
+
- `sendRichMessage`:Telegram rich HTML 发送链路。
|
|
57
|
+
- `/rich`:RichMessage demo。
|
|
58
|
+
- `/diff`:RichMessage details + diff pre/code,失败回退 HTML。
|
|
59
|
+
|
|
60
|
+
尚未接入:
|
|
61
|
+
|
|
62
|
+
- Rich table/status 面板、auth/quota 表格、MCP resource details、rich draft streaming。
|
|
63
|
+
- `sendRichMessageDraft` 的 thinking block 和最终 rich message 持久化。
|
|
64
|
+
|
|
65
|
+
## 功能面盘点
|
|
66
|
+
|
|
67
|
+
| 功能面 | 现状 | 可用 rich 能力 | 建议 |
|
|
68
|
+
| --- | --- | --- | --- |
|
|
69
|
+
| 活动 turn 状态卡 | 普通短文本,频繁编辑 | heading、list、thinking draft | 保持普通状态卡稳定;私聊 draft streaming 后续用 `RichBlockThinking` |
|
|
70
|
+
| Codex streaming 回复 | 分段纯文本为主 | rich draft、paragraph、pre、details | 先不默认切;需要 feature flag 和失败回退 |
|
|
71
|
+
| 归档工具批次 | 已用 expandable blockquote | details、pre、list | 短期维持 HTML;后续 rich details 展开命令、文件、搜索结果 |
|
|
72
|
+
| `/diff` | 已优先 RichMessage,失败回退 HTML | pre language、details | 已落地 |
|
|
73
|
+
| 审批请求 | 多行纯文本 + inline keyboard | code、pre、spoiler、details | 命令、路径、patch 适合 code/pre/details;敏感参数可 spoiler |
|
|
74
|
+
| `/status` / runtime 摘要 | 纯文本列表 | table、heading、footer | 多 bot、多 auth、多 quota 适合 rich table |
|
|
75
|
+
| `/auth` / `/quota` | 紧凑纯文本 + 按钮 | table、marked、spoiler | quota 窗口适合 table;异常候选用 marked;隐藏敏感候选信息需谨慎 |
|
|
76
|
+
| `/threads` / `/setup` | 已用 HTML 面板 | heading、list、anchor | 现状够用;rich message 价值中等 |
|
|
77
|
+
| MCP resource / plugin skill | 纯文本长内容 | details、pre、anchor/reference | schema、resource 文本可放 details/pre,引用可用 anchor/reference |
|
|
78
|
+
| 说明类消息 / help | 纯文本 | heading、list、code | 可转 rich list,但优先级低 |
|
|
79
|
+
| 媒体附件反馈 | 纯文本摘要 | collage/slideshow/photo/video caption | 只在需要回显媒体结果时考虑,当前不是主路径 |
|
|
80
|
+
|
|
81
|
+
## 落地路线
|
|
82
|
+
|
|
83
|
+
### Phase 1:HTML 兼容增强
|
|
84
|
+
|
|
85
|
+
目标:不改变 Bot API 主方法,先改善现有客户端体验。
|
|
86
|
+
|
|
87
|
+
- 统一 Telegram HTML helper,禁止散落手写转义。
|
|
88
|
+
- 长内容默认折叠:diff、工具日志、MCP resource、插件 skill 内容。
|
|
89
|
+
- 命令、路径、模型、候选名使用 `<code>`。
|
|
90
|
+
- 对可能包含 secret/token 的诊断内容使用 `<tg-spoiler>` 或直接不展示。
|
|
91
|
+
|
|
92
|
+
已完成:HTML helper、`/diff` 折叠、现有 CLI/工具归档复用 helper。
|
|
93
|
+
|
|
94
|
+
### Phase 2:Rich Message builder
|
|
95
|
+
|
|
96
|
+
目标:让 rich message 作为可回退能力存在,而不是替换全部消息。
|
|
97
|
+
|
|
98
|
+
已完成:
|
|
99
|
+
|
|
100
|
+
- 新增 `src/telegram/rich.ts`,定义 `InputRichMessage` 的最小 HTML 输入。
|
|
101
|
+
- `TelegramGateway` 增加 `sendRichMessage`、`editRichMessage`、`sendRichMessageDraft`。
|
|
102
|
+
- `TelegramMessagingPort` 和 `BridgeMessagingRouter` 增加 rich HTML send/edit;微信 scope 自动用 fallback HTML。
|
|
103
|
+
- `/rich` 和 `/diff` 先使用 rich 发送,失败回退到 HTML。
|
|
104
|
+
|
|
105
|
+
下一步:
|
|
106
|
+
|
|
107
|
+
- 把 `/status`、`/auth`、`/quota`、MCP resource 等结构消息迁移到 rich table/details。
|
|
108
|
+
- 按真实客户端表现决定是否加入全局配置开关。
|
|
109
|
+
|
|
110
|
+
### Phase 3:Rich draft streaming
|
|
111
|
+
|
|
112
|
+
目标:私聊里的 AI 生成过程更自然。
|
|
113
|
+
|
|
114
|
+
- 仅对 Telegram 私聊启用;群组、topic 默认继续走现有 segmented stream。
|
|
115
|
+
- draft 中使用 `RichBlockThinking` 表示思考中,已生成文本用 paragraph/pre/details。
|
|
116
|
+
- 生成完成后调用 `sendRichMessage` 发送完整消息,不能只依赖 ephemeral draft。
|
|
117
|
+
- 保留旧 `sendMessageDraft` 和 plain segmented stream 回退。
|
|
118
|
+
|
|
119
|
+
## 风险和注意点
|
|
120
|
+
|
|
121
|
+
- Rich Messages 是 2026-06-11 Bot API 10.1 新能力,客户端兼容性需要通过 `/rich` 和 `/diff` 实测。
|
|
122
|
+
- `sendRichMessageDraft` 只面向用户私聊;FoxClaw 的群组、topic、多 bot 场景必须保留旧路径。
|
|
123
|
+
- Rich media block 需要 bot 具备对应发送权限,且媒体 URL/上传处理比文本复杂,暂不作为第一阶段目标。
|
|
124
|
+
- 自动实体识别可能把路径、邮箱、URL、命令误识别;rich builder 应按消息类型决定是否设置 `skip_entity_detection`。
|
|
125
|
+
- HTML/rich 格式必须集中 escape,不能让 Codex 输出或 shell 输出直接拼进标签。
|
package/docs/zh/user-manual.md
CHANGED
|
@@ -265,6 +265,10 @@ TG_ALLOWED_TOPIC_ID=42
|
|
|
265
265
|
|
|
266
266
|
Telegram 会把 HTML 和按钮渲染出来。这里用等宽框模拟实际面板:
|
|
267
267
|
|
|
268
|
+
Telegram Rich Message 能力的专项盘点和后续接入路线见 [Telegram Rich Message 适配专项检查](./telegram-rich-messages.md)。当前默认通道仍优先使用兼容性更稳的 Telegram HTML。
|
|
269
|
+
|
|
270
|
+
可以发送 `/rich` 在当前 Telegram 客户端查看 RichMessage demo。`/diff` 也会优先用 RichMessage 展示 details 和 diff code block,失败时自动回退到 Telegram HTML。
|
|
271
|
+
|
|
268
272
|
```text
|
|
269
273
|
会话偏好
|
|
270
274
|
当前:gpt-5.5 · high · fast=off · default · Agent · Steer current turn
|