@@ -14,6 +14,7 @@ import { buildTelegramOpaqueCallbackData } from "./native-command-callback-data.
1414const {
1515 answerCallbackQuerySpy,
1616 commandSpy,
17+ deleteMessageSpy,
1718 editMessageReplyMarkupSpy,
1819 editMessageTextSpy,
1920 enqueueSystemEventSpy,
@@ -2864,6 +2865,7 @@ describe("createTelegramBot", () => {
28642865 data : "codexapp:resume:thread-1" ,
28652866 from : { id : 9 , first_name : "Ada" , username : "ada_bot" } ,
28662867 message : {
2868+ business_connection_id : "biz-1" ,
28672869 chat : { id : 1234 , type : "private" } ,
28682870 date : 1736380800 ,
28692871 message_id : 11 ,
@@ -2874,7 +2876,132 @@ describe("createTelegramBot", () => {
28742876 getFile : async ( ) => ( { download : async ( ) => new Uint8Array ( ) } ) ,
28752877 } ) ;
28762878
2877- expect ( editMessageTextSpy ) . toHaveBeenCalledWith ( 1234 , 11 , "Handled resume:thread-1" , undefined ) ;
2879+ expect ( editMessageTextSpy ) . toHaveBeenCalledWith ( 1234 , 11 , "Handled resume:thread-1" , {
2880+ business_connection_id : "biz-1" ,
2881+ } ) ;
2882+ expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
2883+ } ) ;
2884+
2885+ it ( "deletes plugin-owned callback messages through the bot API" , async ( ) => {
2886+ onSpy . mockClear ( ) ;
2887+ replySpy . mockClear ( ) ;
2888+ deleteMessageSpy . mockClear ( ) ;
2889+ registerPluginInteractiveHandler ( "codex-plugin" , {
2890+ channel : "telegram" ,
2891+ namespace : "codexapp" ,
2892+ handler : ( async ( { respond } : TelegramInteractiveHandlerContext ) => {
2893+ await respond . deleteMessage ( ) ;
2894+ return { handled : true } ;
2895+ } ) as never ,
2896+ } ) ;
2897+
2898+ createTelegramBot ( {
2899+ token : "tok" ,
2900+ config : {
2901+ channels : {
2902+ telegram : {
2903+ dmPolicy : "open" ,
2904+ allowFrom : [ "*" ] ,
2905+ } ,
2906+ } ,
2907+ } ,
2908+ } ) ;
2909+ const callbackHandler = getOnHandler ( "callback_query" ) as (
2910+ ctx : Record < string , unknown > ,
2911+ ) => Promise < void > ;
2912+
2913+ await callbackHandler ( {
2914+ callbackQuery : {
2915+ id : "cbq-codex-delete" ,
2916+ data : "codexapp:delete:thread-1" ,
2917+ from : { id : 9 , first_name : "Ada" , username : "ada_bot" } ,
2918+ message : {
2919+ chat : { id : 1234 , type : "private" } ,
2920+ date : 1736380800 ,
2921+ message_id : 11 ,
2922+ text : "Select a thread" ,
2923+ } ,
2924+ } ,
2925+ me : { username : "openclaw_bot" } ,
2926+ getFile : async ( ) => ( { download : async ( ) => new Uint8Array ( ) } ) ,
2927+ } ) ;
2928+
2929+ expect ( deleteMessageSpy ) . toHaveBeenCalledWith ( 1234 , 11 ) ;
2930+ expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
2931+ } ) ;
2932+
2933+ it ( "routes plugin-owned callback replies with Telegram topic params" , async ( ) => {
2934+ onSpy . mockClear ( ) ;
2935+ replySpy . mockClear ( ) ;
2936+ sendMessageSpy . mockClear ( ) ;
2937+ registerPluginInteractiveHandler ( "codex-plugin" , {
2938+ channel : "telegram" ,
2939+ namespace : "codexapp" ,
2940+ handler : ( async ( { respond } : TelegramInteractiveHandlerContext ) => {
2941+ await respond . reply ( { text : "Handled in topic" } ) ;
2942+ return { handled : true } ;
2943+ } ) as never ,
2944+ } ) ;
2945+
2946+ createTelegramBot ( {
2947+ token : "tok" ,
2948+ config : {
2949+ channels : {
2950+ telegram : {
2951+ dmPolicy : "open" ,
2952+ allowFrom : [ "*" ] ,
2953+ } ,
2954+ } ,
2955+ } ,
2956+ } ) ;
2957+ const callbackHandler = getOnHandler ( "callback_query" ) as (
2958+ ctx : Record < string , unknown > ,
2959+ ) => Promise < void > ;
2960+
2961+ await callbackHandler ( {
2962+ callbackQuery : {
2963+ id : "cbq-codex-topic-reply" ,
2964+ data : "codexapp:reply:thread-1" ,
2965+ from : { id : 9 , first_name : "Ada" , username : "ada_bot" } ,
2966+ message : {
2967+ business_connection_id : "biz-topic-1" ,
2968+ chat : { id : - 100987654321 , type : "supergroup" , title : "Forum Group" } ,
2969+ date : 1736380800 ,
2970+ is_topic_message : true ,
2971+ message_id : 11 ,
2972+ message_thread_id : 99 ,
2973+ text : "Select a thread" ,
2974+ } ,
2975+ } ,
2976+ me : { username : "openclaw_bot" } ,
2977+ getFile : async ( ) => ( { download : async ( ) => new Uint8Array ( ) } ) ,
2978+ } ) ;
2979+
2980+ expect ( sendMessageSpy ) . toHaveBeenCalledWith ( - 100987654321 , "Handled in topic" , {
2981+ business_connection_id : "biz-topic-1" ,
2982+ message_thread_id : 99 ,
2983+ } ) ;
2984+
2985+ sendMessageSpy . mockClear ( ) ;
2986+ await callbackHandler ( {
2987+ callbackQuery : {
2988+ id : "cbq-codex-general-reply" ,
2989+ data : "codexapp:reply:thread-1" ,
2990+ from : { id : 9 , first_name : "Ada" , username : "ada_bot" } ,
2991+ message : {
2992+ chat : { id : - 100987654322 , type : "supergroup" , title : "Forum Group" } ,
2993+ date : 1736380800 ,
2994+ is_topic_message : true ,
2995+ message_id : 12 ,
2996+ message_thread_id : 1 ,
2997+ text : "Select a thread" ,
2998+ } ,
2999+ } ,
3000+ me : { username : "openclaw_bot" } ,
3001+ getFile : async ( ) => ( { download : async ( ) => new Uint8Array ( ) } ) ,
3002+ } ) ;
3003+
3004+ expect ( sendMessageSpy ) . toHaveBeenCalledWith ( - 100987654322 , "Handled in topic" , undefined ) ;
28783005 expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
28793006 } ) ;
28803007
0 commit comments