fix: keep telegram dm thread sessions (#2731) (thanks @dylanneve1)
This commit is contained in:
parent
915497114e
commit
14e4b88bf0
@ -95,6 +95,7 @@ Status: beta.
|
|||||||
- Agents: release session locks on process termination and cover more signals. (#2483) Thanks @janeexai.
|
- Agents: release session locks on process termination and cover more signals. (#2483) Thanks @janeexai.
|
||||||
- Agents: skip cooldowned providers during model failover. (#2143) Thanks @YiWang24.
|
- Agents: skip cooldowned providers during model failover. (#2143) Thanks @YiWang24.
|
||||||
- Telegram: harden polling + retry behavior for transient network errors and Node 22 transport issues. (#2420) Thanks @techboss.
|
- Telegram: harden polling + retry behavior for transient network errors and Node 22 transport issues. (#2420) Thanks @techboss.
|
||||||
|
- Telegram: ignore non-forum group message_thread_id while preserving DM thread sessions. (#2731) Thanks @dylanneve1.
|
||||||
- Telegram: wrap reasoning italics per line to avoid raw underscores. (#2181) Thanks @YuriNachos.
|
- Telegram: wrap reasoning italics per line to avoid raw underscores. (#2181) Thanks @YuriNachos.
|
||||||
- Telegram: centralize API error logging for delivery and bot calls. (#2492) Thanks @altryne.
|
- Telegram: centralize API error logging for delivery and bot calls. (#2492) Thanks @altryne.
|
||||||
- Voice Call: enforce Twilio webhook signature verification for ngrok URLs; disable ngrok free tier bypass by default.
|
- Voice Call: enforce Twilio webhook signature verification for ngrok URLs; disable ngrok free tier bypass by default.
|
||||||
|
|||||||
@ -360,6 +360,8 @@ export const registerTelegramNativeCommands = ({
|
|||||||
topicConfig,
|
topicConfig,
|
||||||
commandAuthorized,
|
commandAuthorized,
|
||||||
} = auth;
|
} = auth;
|
||||||
|
const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id;
|
||||||
|
const threadIdForSend = isGroup ? resolvedThreadId : messageThreadId;
|
||||||
|
|
||||||
const commandDefinition = findCommandByNativeName(command.name, "telegram");
|
const commandDefinition = findCommandByNativeName(command.name, "telegram");
|
||||||
const rawText = ctx.match?.trim() ?? "";
|
const rawText = ctx.match?.trim() ?? "";
|
||||||
@ -406,7 +408,7 @@ export const registerTelegramNativeCommands = ({
|
|||||||
fn: () =>
|
fn: () =>
|
||||||
bot.api.sendMessage(chatId, title, {
|
bot.api.sendMessage(chatId, title, {
|
||||||
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
||||||
...(resolvedThreadId != null ? { message_thread_id: resolvedThreadId } : {}),
|
...(threadIdForSend != null ? { message_thread_id: threadIdForSend } : {}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -467,7 +469,7 @@ export const registerTelegramNativeCommands = ({
|
|||||||
CommandSource: "native" as const,
|
CommandSource: "native" as const,
|
||||||
SessionKey: `telegram:slash:${senderId || chatId}`,
|
SessionKey: `telegram:slash:${senderId || chatId}`,
|
||||||
CommandTargetSessionKey: sessionKey,
|
CommandTargetSessionKey: sessionKey,
|
||||||
MessageThreadId: resolvedThreadId,
|
MessageThreadId: threadIdForSend,
|
||||||
IsForum: isForum,
|
IsForum: isForum,
|
||||||
// Originating context for sub-agent announce routing
|
// Originating context for sub-agent announce routing
|
||||||
OriginatingChannel: "telegram" as const,
|
OriginatingChannel: "telegram" as const,
|
||||||
@ -494,7 +496,7 @@ export const registerTelegramNativeCommands = ({
|
|||||||
bot,
|
bot,
|
||||||
replyToMode,
|
replyToMode,
|
||||||
textLimit,
|
textLimit,
|
||||||
messageThreadId: resolvedThreadId,
|
messageThreadId: threadIdForSend,
|
||||||
tableMode,
|
tableMode,
|
||||||
chunkMode,
|
chunkMode,
|
||||||
linkPreview: telegramCfg.linkPreview,
|
linkPreview: telegramCfg.linkPreview,
|
||||||
@ -542,7 +544,9 @@ export const registerTelegramNativeCommands = ({
|
|||||||
requireAuth: match.command.requireAuth !== false,
|
requireAuth: match.command.requireAuth !== false,
|
||||||
});
|
});
|
||||||
if (!auth) return;
|
if (!auth) return;
|
||||||
const { resolvedThreadId, senderId, commandAuthorized } = auth;
|
const { resolvedThreadId, senderId, commandAuthorized, isGroup } = auth;
|
||||||
|
const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id;
|
||||||
|
const threadIdForSend = isGroup ? resolvedThreadId : messageThreadId;
|
||||||
|
|
||||||
const result = await executePluginCommand({
|
const result = await executePluginCommand({
|
||||||
command: match.command,
|
command: match.command,
|
||||||
@ -568,7 +572,7 @@ export const registerTelegramNativeCommands = ({
|
|||||||
bot,
|
bot,
|
||||||
replyToMode,
|
replyToMode,
|
||||||
textLimit,
|
textLimit,
|
||||||
messageThreadId: resolvedThreadId,
|
messageThreadId: threadIdForSend,
|
||||||
tableMode,
|
tableMode,
|
||||||
chunkMode,
|
chunkMode,
|
||||||
linkPreview: telegramCfg.linkPreview,
|
linkPreview: telegramCfg.linkPreview,
|
||||||
|
|||||||
@ -238,12 +238,17 @@ describe("createTelegramBot", () => {
|
|||||||
expect(getTelegramSequentialKey({ message: { chat: { id: 123 } } })).toBe("telegram:123");
|
expect(getTelegramSequentialKey({ message: { chat: { id: 123 } } })).toBe("telegram:123");
|
||||||
expect(
|
expect(
|
||||||
getTelegramSequentialKey({
|
getTelegramSequentialKey({
|
||||||
message: { chat: { id: 123 }, message_thread_id: 9 },
|
message: { chat: { id: 123, type: "private" }, message_thread_id: 9 },
|
||||||
}),
|
}),
|
||||||
).toBe("telegram:123:topic:9");
|
).toBe("telegram:123:topic:9");
|
||||||
expect(
|
expect(
|
||||||
getTelegramSequentialKey({
|
getTelegramSequentialKey({
|
||||||
message: { chat: { id: 123, is_forum: true } },
|
message: { chat: { id: 123, type: "supergroup" }, message_thread_id: 9 },
|
||||||
|
}),
|
||||||
|
).toBe("telegram:123");
|
||||||
|
expect(
|
||||||
|
getTelegramSequentialKey({
|
||||||
|
message: { chat: { id: 123, type: "supergroup", is_forum: true } },
|
||||||
}),
|
}),
|
||||||
).toBe("telegram:123:topic:1");
|
).toBe("telegram:123:topic:1");
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@ -340,12 +340,17 @@ describe("createTelegramBot", () => {
|
|||||||
expect(getTelegramSequentialKey({ message: { chat: { id: 123 } } })).toBe("telegram:123");
|
expect(getTelegramSequentialKey({ message: { chat: { id: 123 } } })).toBe("telegram:123");
|
||||||
expect(
|
expect(
|
||||||
getTelegramSequentialKey({
|
getTelegramSequentialKey({
|
||||||
message: { chat: { id: 123 }, message_thread_id: 9 },
|
message: { chat: { id: 123, type: "private" }, message_thread_id: 9 },
|
||||||
}),
|
}),
|
||||||
).toBe("telegram:123:topic:9");
|
).toBe("telegram:123:topic:9");
|
||||||
expect(
|
expect(
|
||||||
getTelegramSequentialKey({
|
getTelegramSequentialKey({
|
||||||
message: { chat: { id: 123, is_forum: true } },
|
message: { chat: { id: 123, type: "supergroup" }, message_thread_id: 9 },
|
||||||
|
}),
|
||||||
|
).toBe("telegram:123");
|
||||||
|
expect(
|
||||||
|
getTelegramSequentialKey({
|
||||||
|
message: { chat: { id: 123, type: "supergroup", is_forum: true } },
|
||||||
}),
|
}),
|
||||||
).toBe("telegram:123:topic:1");
|
).toBe("telegram:123:topic:1");
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@ -94,11 +94,12 @@ export function getTelegramSequentialKey(ctx: {
|
|||||||
if (typeof chatId === "number") return `telegram:${chatId}:control`;
|
if (typeof chatId === "number") return `telegram:${chatId}:control`;
|
||||||
return "telegram:control";
|
return "telegram:control";
|
||||||
}
|
}
|
||||||
|
const isGroup = msg?.chat?.type === "group" || msg?.chat?.type === "supergroup";
|
||||||
|
const messageThreadId = msg?.message_thread_id;
|
||||||
const isForum = (msg?.chat as { is_forum?: boolean } | undefined)?.is_forum;
|
const isForum = (msg?.chat as { is_forum?: boolean } | undefined)?.is_forum;
|
||||||
const threadId = resolveTelegramForumThreadId({
|
const threadId = isGroup
|
||||||
isForum,
|
? resolveTelegramForumThreadId({ isForum, messageThreadId })
|
||||||
messageThreadId: msg?.message_thread_id,
|
: messageThreadId;
|
||||||
});
|
|
||||||
if (typeof chatId === "number") {
|
if (typeof chatId === "number") {
|
||||||
return threadId != null ? `telegram:${chatId}:topic:${threadId}` : `telegram:${chatId}`;
|
return threadId != null ? `telegram:${chatId}:topic:${threadId}` : `telegram:${chatId}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user