@@ -88,7 +88,7 @@ describe("buildTelegramMessageContext dm thread sessions", () => {
8888 message : Record < string , unknown > ,
8989 params ?: Pick <
9090 Parameters < typeof buildTelegramMessageContextForTest > [ 0 ] ,
91- "cfg" | "me" | "resolveTelegramGroupConfig"
91+ "cfg" | "me" | "resolveTelegramGroupConfig" | "sendChatActionHandler"
9292 > ,
9393 ) =>
9494 await buildTelegramMessageContextForTest ( {
@@ -130,7 +130,7 @@ describe("buildTelegramMessageContext dm thread sessions", () => {
130130 expect ( ctx ?. ctxPayload ?. SessionKey ) . toBe ( "agent:main:main:thread:1234:42" ) ;
131131 } ) ;
132132
133- it ( "does not use configured DM topics without bot topic capability" , async ( ) => {
133+ it ( "does not use configured bot-private topics without bot topic capability" , async ( ) => {
134134 const ctx = await buildContext (
135135 {
136136 ...dmThreadMessage ,
@@ -149,7 +149,7 @@ describe("buildTelegramMessageContext dm thread sessions", () => {
149149 expect ( ctx ?. ctxPayload ?. SessionKey ) . toBe ( "agent:support:main" ) ;
150150 } ) ;
151151
152- it ( "uses configured DM topic routing once bot topic capability is present" , async ( ) => {
152+ it ( "uses configured bot-private topic routing once bot topic capability is present" , async ( ) => {
153153 const ctx = await buildContext (
154154 {
155155 ...dmThreadMessage ,
@@ -184,11 +184,18 @@ describe("buildTelegramMessageContext dm thread sessions", () => {
184184} ) ;
185185
186186describe ( "buildTelegramMessageContext group sessions without forum" , ( ) => {
187- const buildContext = async ( message : Record < string , unknown > ) =>
187+ const buildContext = async (
188+ message : Record < string , unknown > ,
189+ params ?: Pick <
190+ Parameters < typeof buildTelegramMessageContextForTest > [ 0 ] ,
191+ "sendChatActionHandler"
192+ > ,
193+ ) =>
188194 await buildTelegramMessageContextForTest ( {
189195 message,
190196 options : { forceWasMentioned : true } ,
191197 resolveGroupActivation : ( ) => true ,
198+ ...params ,
192199 } ) ;
193200
194201 it ( "ignores message_thread_id for regular groups (not forums)" , async ( ) => {
@@ -212,6 +219,45 @@ describe("buildTelegramMessageContext group sessions without forum", () => {
212219 expect ( ctx . ctxPayload . MessageThreadId ) . toBeUndefined ( ) ;
213220 } ) ;
214221
222+ it ( "round-trips channel Direct Messages topics with their distinct target marker" , async ( ) => {
223+ const sendChatAction = vi . fn ( async ( ) => undefined ) ;
224+ const ctx = await buildContext (
225+ {
226+ message_id : 8 ,
227+ chat : {
228+ id : - 1001234567890 ,
229+ type : "supergroup" ,
230+ title : "Channel Direct Messages" ,
231+ is_direct_messages : true ,
232+ } ,
233+ date : 1700000007 ,
234+ text : "@bot hello" ,
235+ message_thread_id : 999 ,
236+ direct_messages_topic : {
237+ topic_id : 77 ,
238+ user : { id : 700 , is_bot : false , first_name : "Subscriber" } ,
239+ } ,
240+ from : { id : 700 , first_name : "Subscriber" } ,
241+ } ,
242+ {
243+ sendChatActionHandler : {
244+ sendChatAction,
245+ isSuspended : ( ) => false ,
246+ reset : ( ) => { } ,
247+ } ,
248+ } ,
249+ ) ;
250+
251+ expect ( ctx ?. ctxPayload . MessageThreadId ) . toBe ( 77 ) ;
252+ expect ( ctx ?. ctxPayload . OriginatingTo ) . toBe ( "telegram:-1001234567890:direct-topic:77" ) ;
253+ expect ( ctx ?. ctxPayload . SessionKey ) . toBe ( "agent:main:telegram:group:-1001234567890:topic:77" ) ;
254+ expect ( ctx ?. turn . record . updateLastRoute ) . toMatchObject ( {
255+ to : "telegram:-1001234567890:direct-topic:77" ,
256+ threadId : "77" ,
257+ } ) ;
258+ expect ( sendChatAction ) . not . toHaveBeenCalled ( ) ;
259+ } ) ;
260+
215261 it ( "carries the body-layer inbound event kind instead of restamping from copied mention booleans" , async ( ) => {
216262 inboundBodyResult . value = {
217263 ...inboundBodyResult . reset ( ) ,
0 commit comments