@@ -716,6 +716,7 @@ describe("dispatchTelegramMessage draft streaming", () => {
716716 historyKey : oldHistoryKey ,
717717 historyLimit : 10 ,
718718 groupHistories,
719+ groupHistoryContextMode : "recent" ,
719720 sendChatActionHandler,
720721 turn : {
721722 storePath : "/tmp/openclaw/telegram-sessions.json" ,
@@ -776,6 +777,90 @@ describe("dispatchTelegramMessage draft streaming", () => {
776777 expect ( deliverReplies ) . not . toHaveBeenCalled ( ) ;
777778 } ) ;
778779
780+ it . each ( [ "mention-only" , "none" ] as const ) (
781+ "does not recover forum history context when mode is %s" ,
782+ async ( groupHistoryContextMode ) => {
783+ const oldHistoryKey = "-1003774691294:topic:1" ;
784+ const recoveredHistoryKey = "-1003774691294:topic:3731" ;
785+ const groupHistories = new Map ( [
786+ [ oldHistoryKey , [ { sender : "Alice" , body : "general topic context" , timestamp : 1 } ] ] ,
787+ [ recoveredHistoryKey , [ { sender : "Bob" , body : "recovered topic context" , timestamp : 2 } ] ] ,
788+ ] ) ;
789+ deliverInboundReplyWithMessageSendContext . mockResolvedValue ( {
790+ status : "handled_visible" ,
791+ delivery : {
792+ messageIds : [ "3731" ] ,
793+ visibleReplySent : true ,
794+ } ,
795+ } ) ;
796+ dispatchReplyWithBufferedBlockDispatcher . mockImplementation ( async ( { dispatcherOptions } ) => {
797+ await dispatcherOptions . deliver ( { text : "topic final" } , { kind : "final" } ) ;
798+ return { queuedFinal : true } ;
799+ } ) ;
800+
801+ await dispatchWithContext ( {
802+ context : createContext ( {
803+ ctxPayload : {
804+ Body :
805+ "[Chat messages since your last reply - for context]\n" +
806+ "general topic context\n" +
807+ "[Current message - respond to this]\n" +
808+ "current topic question" ,
809+ BodyForAgent :
810+ "[Chat messages since your last reply - for context]\n" +
811+ "general topic context\n" +
812+ "[Current message - respond to this]\n" +
813+ "current topic question" ,
814+ ChatType : "group" ,
815+ From : "telegram:group:-1003774691294:topic:1" ,
816+ MessageThreadId : 1 ,
817+ OriginatingTo : "telegram:-1003774691294" ,
818+ SessionKey : "agent:main:telegram:group:-1003774691294:topic:3731" ,
819+ To : "telegram:-1003774691294" ,
820+ TransportThreadId : 1 ,
821+ } as unknown as TelegramMessageContext [ "ctxPayload" ] ,
822+ msg : {
823+ chat : { id : - 1003774691294 , type : "supergroup" } ,
824+ message_id : 27787 ,
825+ message_thread_id : undefined ,
826+ } as unknown as TelegramMessageContext [ "msg" ] ,
827+ primaryCtx : {
828+ message : { chat : { id : - 1003774691294 , type : "supergroup" } } ,
829+ } as unknown as TelegramMessageContext [ "primaryCtx" ] ,
830+ chatId : - 1003774691294 ,
831+ isGroup : true ,
832+ replyThreadId : undefined ,
833+ resolvedThreadId : undefined ,
834+ threadSpec : { id : 1 , scope : "forum" } ,
835+ historyKey : oldHistoryKey ,
836+ historyLimit : 10 ,
837+ groupHistories,
838+ groupHistoryContextMode,
839+ } ) ,
840+ replyToMode : "off" ,
841+ streamMode : "off" ,
842+ } ) ;
843+
844+ const outbound = expectRecordFields ( mockCallArg ( deliverInboundReplyWithMessageSendContext ) , {
845+ threadId : 3731 ,
846+ } ) ;
847+ expectRecordFields ( outbound . ctxPayload , {
848+ From : "telegram:group:-1003774691294:topic:3731" ,
849+ MessageThreadId : 3731 ,
850+ OriginatingTo : "telegram:-1003774691294:topic:3731" ,
851+ TransportThreadId : 3731 ,
852+ To : "telegram:-1003774691294:topic:3731" ,
853+ } ) ;
854+ const outboundCtxPayload = expectRecordFields ( outbound . ctxPayload , { } ) ;
855+ expect ( outboundCtxPayload . InboundHistory ) . toBeUndefined ( ) ;
856+ expect ( outboundCtxPayload . Body ) . toBe ( "current topic question" ) ;
857+ expect ( outboundCtxPayload . Body ) . not . toContain ( "recovered topic context" ) ;
858+ expect ( outboundCtxPayload . Body ) . not . toContain ( "general topic context" ) ;
859+ expect ( outboundCtxPayload . BodyForAgent ) . toBe ( "current topic question" ) ;
860+ expect ( deliverReplies ) . not . toHaveBeenCalled ( ) ;
861+ } ,
862+ ) ;
863+
779864 it ( "does not recover forum thread context from malformed payload thread ids" , async ( ) => {
780865 const generalHistoryKey = "-1003774691294:topic:1" ;
781866 const spoofedHistoryKey = "-1003774691294:topic:3731" ;
@@ -955,6 +1040,7 @@ describe("dispatchTelegramMessage draft streaming", () => {
9551040 historyKey : oldHistoryKey ,
9561041 historyLimit : 10 ,
9571042 groupHistories,
1043+ groupHistoryContextMode : "recent" ,
9581044 } ) ,
9591045 replyToMode : "off" ,
9601046 streamMode : "off" ,
0 commit comments