@@ -671,6 +671,18 @@ export const dispatchTelegramMessage = async ({
671671 } ;
672672 const silentErrorReplies = telegramCfg . silentErrorReplies === true ;
673673 const isDmTopic = ! isGroup && threadSpec . scope === "dm" && threadSpec . id != null ;
674+ const policySessionKey =
675+ ctxPayload . CommandSource === "native"
676+ ? ( ctxPayload . CommandTargetSessionKey ?? ctxPayload . SessionKey )
677+ : ctxPayload . SessionKey ;
678+ const trustPolicyThreadSessionKey = isTrustedTelegramPolicyThreadSessionKey ( {
679+ sessionKey : policySessionKey ,
680+ chatId,
681+ thread : threadSpec ,
682+ } ) ;
683+ const dispatchCtxPayload = trustPolicyThreadSessionKey
684+ ? { ...ctxPayload , TrustedThreadSessionKey : true }
685+ : ctxPayload ;
674686 let queuedFinal = false ;
675687 let hadErrorReplyFailureOrSkip = false ;
676688 let isFirstTurnInSession = false ;
@@ -870,10 +882,21 @@ export const dispatchTelegramMessage = async ({
870882 record : context . turn . record ,
871883 runDispatch : ( ) =>
872884 telegramDeps . dispatchReplyWithBufferedBlockDispatcher ( {
873- ctx : ctxPayload ,
885+ ctx : dispatchCtxPayload ,
874886 cfg,
875887 dispatcherOptions : {
876888 ...replyPipeline ,
889+ ...( trustPolicyThreadSessionKey
890+ ? {
891+ silentReplyContext : {
892+ cfg,
893+ sessionKey : policySessionKey ,
894+ surface : "telegram" ,
895+ conversationType : "internal" as const ,
896+ trustThreadSessionKey : true ,
897+ } ,
898+ }
899+ : { } ) ,
877900 beforeDeliver : async ( payload ) => payload ,
878901 deliver : async ( payload , info ) => {
879902 if ( isDispatchSuperseded ( ) ) {
@@ -1308,15 +1331,6 @@ export const dispatchTelegramMessage = async ({
13081331 }
13091332
13101333 if ( ! queuedFinal && ! sentFallback && ! dispatchError && ! deliverySummary . delivered ) {
1311- const policySessionKey =
1312- ctxPayload . CommandSource === "native"
1313- ? ( ctxPayload . CommandTargetSessionKey ?? ctxPayload . SessionKey )
1314- : ctxPayload . SessionKey ;
1315- const trustPolicyThreadSessionKey = isTrustedTelegramPolicyThreadSessionKey ( {
1316- sessionKey : policySessionKey ,
1317- chatId,
1318- thread : threadSpec ,
1319- } ) ;
13201334 const silentReplyFallback = projectOutboundPayloadPlanForDelivery (
13211335 createOutboundPayloadPlan ( [ { text : "NO_REPLY" } ] , {
13221336 cfg,
0 commit comments