telegram: route dm sessions by sender id

This commit is contained in:
bmendonca3
2026-03-02 14:56:26 -07:00
committed by Peter Steinberger
parent 2c39731846
commit 317075ef3d
4 changed files with 82 additions and 3 deletions

View File

@@ -52,6 +52,7 @@ import {
buildGroupLabel,
buildSenderLabel,
buildSenderName,
resolveTelegramDirectPeerId,
buildTelegramGroupFrom,
buildTelegramGroupPeerId,
buildTelegramParentPeer,
@@ -174,6 +175,7 @@ export const buildTelegramMessageContext = async ({
const msg = primaryCtx.message;
const chatId = msg.chat.id;
const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup";
const senderId = msg.from?.id ? String(msg.from.id) : "";
const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id;
const isForum = (msg.chat as { is_forum?: boolean }).is_forum === true;
const threadSpec = resolveTelegramThreadSpec({
@@ -191,7 +193,9 @@ export const buildTelegramMessageContext = async ({
!isGroup && groupConfig && "dmPolicy" in groupConfig
? (groupConfig.dmPolicy ?? dmPolicy)
: dmPolicy;
const peerId = isGroup ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : String(chatId);
const peerId = isGroup
? buildTelegramGroupPeerId(chatId, resolvedThreadId)
: resolveTelegramDirectPeerId({ chatId, senderId });
const parentPeer = buildTelegramParentPeer({ isGroup, resolvedThreadId, chatId });
// Fresh config for bindings lookup; other routing inputs are payload-derived.
const route = resolveAgentRoute({
@@ -235,7 +239,6 @@ export const buildTelegramMessageContext = async ({
// Group sender checks are explicit and must not inherit DM pairing-store entries.
const effectiveGroupAllow = normalizeAllowFrom(groupAllowOverride ?? groupAllowFrom);
const hasGroupAllowOverride = typeof groupAllowOverride !== "undefined";
const senderId = msg.from?.id ? String(msg.from.id) : "";
const senderUsername = msg.from?.username ?? "";
const baseAccess = evaluateTelegramGroupBaseAccess({
isGroup,