diff --git a/CHANGELOG.md b/CHANGELOG.md index 79164fbec0..27b8e642ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ Status: stable. - Telegram: avoid silent empty replies by tracking normalization skips before fallback. (#3796) - Telegram: accept numeric messageId/chatId in react action and honor channelId fallback. (#4533) Thanks @Ayush10. - Telegram: scope native skill commands to bound agent per bot. (#4360) Thanks @robhparker. +- Telegram: fall back to session origin thread id for delivery context when missing. (#4911) Thanks @yevhen. - Mentions: honor mentionPatterns even when explicit mentions are present. (#3303) Thanks @HirokiKobayashi-R. - Discord: restore username directory lookup in target resolution. (#3131) Thanks @bonald. - Agents: align MiniMax base URL test expectation with default provider config. (#3131) Thanks @bonald. diff --git a/src/config/sessions/store.ts b/src/config/sessions/store.ts index a4a0dbf8b5..da581fff01 100644 --- a/src/config/sessions/store.ts +++ b/src/config/sessions/store.ts @@ -60,7 +60,7 @@ function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry { lastChannel: entry.lastChannel, lastTo: entry.lastTo, lastAccountId: entry.lastAccountId, - lastThreadId: entry.lastThreadId ?? entry.origin?.threadId, + lastThreadId: entry.lastThreadId ?? entry.deliveryContext?.threadId ?? entry.origin?.threadId, deliveryContext: entry.deliveryContext, }); const nextDelivery = normalized.deliveryContext; diff --git a/src/utils/delivery-context.test.ts b/src/utils/delivery-context.test.ts index e89d965057..e0c7e71c4c 100644 --- a/src/utils/delivery-context.test.ts +++ b/src/utils/delivery-context.test.ts @@ -88,6 +88,20 @@ describe("delivery context helpers", () => { accountId: undefined, threadId: 42, }); + + expect( + deliveryContextFromSession({ + channel: "telegram", + lastTo: " -1001 ", + deliveryContext: { threadId: " 777 " }, + origin: { threadId: 42 }, + }), + ).toEqual({ + channel: "telegram", + to: "-1001", + accountId: undefined, + threadId: "777", + }); }); it("normalizes delivery fields and mirrors them on session entries", () => { diff --git a/src/utils/delivery-context.ts b/src/utils/delivery-context.ts index 5e9db288be..61a8c08c15 100644 --- a/src/utils/delivery-context.ts +++ b/src/utils/delivery-context.ts @@ -98,7 +98,7 @@ export function deliveryContextFromSession( lastChannel: entry.lastChannel, lastTo: entry.lastTo, lastAccountId: entry.lastAccountId, - lastThreadId: entry.lastThreadId ?? entry.origin?.threadId, + lastThreadId: entry.lastThreadId ?? entry.deliveryContext?.threadId ?? entry.origin?.threadId, deliveryContext: entry.deliveryContext, }; return normalizeSessionDeliveryFields(source).deliveryContext;