fix: preserve Telegram compatibility and stabilize Office

This commit is contained in:
xmanrui 2026-08-21 01:37:21 +08:00
parent 7f114e1c36
commit 24e690498b
23 changed files with 1679 additions and 314 deletions

View file

@ -27,7 +27,9 @@ export const TOKEN_BOT_ENDPOINTS = Object.freeze({
setWorkspace: 'bot.workspace.set',
});
export function createTokenChannelApi(channel, connectionSummary) {
export function createTokenChannelApi(channel, connectionSummary, {
normalizeBotExtension = () => ({}),
} = {}) {
const unwrapRpcResult = (result) => {
if (!isRecord(result) || typeof result.ok !== 'boolean') {
throw new Error(`${channel} 服务返回了无法识别的响应`);
@ -44,6 +46,7 @@ export function createTokenChannelApi(channel, connectionSummary) {
if (!isRecord(value) || !id(value.botId)) return undefined;
const connected = value.connected === true;
const state = ACCOUNT_STATES.has(value.state) ? value.state : 'offline';
const extension = normalizeBotExtension(value);
return {
botId: id(value.botId),
connected,
@ -65,6 +68,7 @@ export function createTokenChannelApi(channel, connectionSummary) {
code: text(value.error.code, `${channel.toUpperCase()}_ACCOUNT_ERROR`, 80),
message: text(value.error.message, `${channel}连接尚未就绪`),
} : null,
...(isRecord(extension) ? extension : {}),
};
};