mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 23:46:38 +00:00
feat(telegram): improve DM topics support (#30579) (thanks @kesor)
This commit is contained in:
@@ -293,7 +293,9 @@ function resolveTelegramSession(
|
||||
(chatType === "unknown" &&
|
||||
params.resolvedTarget?.kind &&
|
||||
params.resolvedTarget.kind !== "user");
|
||||
const peerId = isGroup ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : chatId;
|
||||
// For groups: include thread ID in peerId. For DMs: use simple chatId (thread handled via suffix).
|
||||
const peerId =
|
||||
isGroup && resolvedThreadId ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : chatId;
|
||||
const peer: RoutePeer = {
|
||||
kind: isGroup ? "group" : "direct",
|
||||
id: peerId,
|
||||
@@ -305,12 +307,21 @@ function resolveTelegramSession(
|
||||
accountId: params.accountId,
|
||||
peer,
|
||||
});
|
||||
// Use thread suffix for DM topics to match inbound session key format
|
||||
const threadKeys =
|
||||
resolvedThreadId && !isGroup
|
||||
? { sessionKey: `${baseSessionKey}:thread:${resolvedThreadId}` }
|
||||
: null;
|
||||
return {
|
||||
sessionKey: baseSessionKey,
|
||||
sessionKey: threadKeys?.sessionKey ?? baseSessionKey,
|
||||
baseSessionKey,
|
||||
peer,
|
||||
chatType: isGroup ? "group" : "direct",
|
||||
from: isGroup ? `telegram:group:${peerId}` : `telegram:${chatId}`,
|
||||
from: isGroup
|
||||
? `telegram:group:${peerId}`
|
||||
: resolvedThreadId
|
||||
? `telegram:${chatId}:topic:${resolvedThreadId}`
|
||||
: `telegram:${chatId}`,
|
||||
to: `telegram:${chatId}`,
|
||||
threadId: resolvedThreadId,
|
||||
};
|
||||
|
||||
@@ -925,6 +925,19 @@ describe("resolveOutboundSessionRoute", () => {
|
||||
threadId: 42,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Telegram DM with topic",
|
||||
cfg: perChannelPeerCfg,
|
||||
channel: "telegram",
|
||||
target: "123456789:topic:99",
|
||||
expected: {
|
||||
sessionKey: "agent:main:telegram:direct:123456789:thread:99",
|
||||
from: "telegram:123456789:topic:99",
|
||||
to: "telegram:123456789",
|
||||
threadId: 99,
|
||||
chatType: "direct",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Telegram unresolved username DM",
|
||||
cfg: perChannelPeerCfg,
|
||||
|
||||
Reference in New Issue
Block a user