@@ -1806,44 +1806,54 @@ describe("createTelegramBot", () => {
18061806 expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-1" ) ;
18071807 } ) ;
18081808
1809- it ( "routes plugin callback_query payloads to plugin handlers without fallback callback_data text" , async ( ) => {
1810- const pluginHandler = vi . fn ( async ( ctx ) => {
1811- expect ( ctx . callback . namespace ) . toBe ( "code-agent" ) ;
1812- expect ( ctx . callback . payload ) . toBe ( "approve-123" ) ;
1813- await ctx . respond . clearButtons ( ) ;
1814- return { handled : true } ;
1815- } ) ;
1816- expect (
1817- registerPluginInteractiveHandler ( "openclaw-code-agent" , {
1818- channel : "telegram" ,
1819- namespace : "code-agent" ,
1820- handler : pluginHandler ,
1821- } ) ,
1822- ) . toEqual ( { ok : true } ) ;
1809+ it . each ( [
1810+ { name : "raw" , data : "code-agent:approve-123" , payload : "approve-123" } ,
1811+ {
1812+ name : "opaque with trailing whitespace" ,
1813+ data : buildTelegramOpaqueCallbackData ( "code-agent:approve-123 " ) ,
1814+ payload : "approve-123" ,
1815+ } ,
1816+ ] ) (
1817+ "routes $name plugin callback_query payloads without fallback callback_data text" ,
1818+ async ( { data, payload } ) => {
1819+ const pluginHandler = vi . fn ( async ( ctx ) => {
1820+ expect ( ctx . callback . namespace ) . toBe ( "code-agent" ) ;
1821+ expect ( ctx . callback . payload ) . toBe ( payload ) ;
1822+ await ctx . respond . clearButtons ( ) ;
1823+ return { handled : true } ;
1824+ } ) ;
1825+ expect (
1826+ registerPluginInteractiveHandler ( "openclaw-code-agent" , {
1827+ channel : "telegram" ,
1828+ namespace : "code-agent" ,
1829+ handler : pluginHandler ,
1830+ } ) ,
1831+ ) . toEqual ( { ok : true } ) ;
18231832
1824- createTelegramBot ( { token : "tok" } ) ;
1825- const callbackHandler = getCallbackHandler ( ) ;
1826- await callbackHandler (
1827- makeCallbackRetryContext ( {
1828- id : "cbq-plugin-1" ,
1829- data : "code-agent:approve-123" ,
1830- messageId : 10 ,
1831- text : "Approve this code-agent action?" ,
1832- message : {
1833- reply_markup : {
1834- inline_keyboard : [ [ { text : "Approve" , callback_data : "code-agent:approve-123" } ] ] ,
1833+ createTelegramBot ( { token : "tok" } ) ;
1834+ const callbackHandler = getCallbackHandler ( ) ;
1835+ await callbackHandler (
1836+ makeCallbackRetryContext ( {
1837+ id : "cbq-plugin-1" ,
1838+ data,
1839+ messageId : 10 ,
1840+ text : "Approve this code-agent action?" ,
1841+ message : {
1842+ reply_markup : {
1843+ inline_keyboard : [ [ { text : "Approve" , callback_data : data } ] ] ,
1844+ } ,
18351845 } ,
1836- } ,
1837- } ) ,
1838- ) ;
1846+ } ) ,
1847+ ) ;
18391848
1840- expect ( pluginHandler ) . toHaveBeenCalledTimes ( 1 ) ;
1841- expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
1842- expect ( editMessageReplyMarkupSpy ) . toHaveBeenCalledWith ( 1234 , 10 , {
1843- reply_markup : { inline_keyboard : [ ] } ,
1844- } ) ;
1845- expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-plugin-1" ) ;
1846- } ) ;
1849+ expect ( pluginHandler ) . toHaveBeenCalledTimes ( 1 ) ;
1850+ expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
1851+ expect ( editMessageReplyMarkupSpy ) . toHaveBeenCalledWith ( 1234 , 10 , {
1852+ reply_markup : { inline_keyboard : [ ] } ,
1853+ } ) ;
1854+ expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-plugin-1" ) ;
1855+ } ,
1856+ ) ;
18471857
18481858 it ( "preserves raw tgcb1 callbacks emitted before the prefix became reserved" , async ( ) => {
18491859 const pluginHandler = vi . fn ( async ( ctx ) => {
@@ -1957,32 +1967,39 @@ describe("createTelegramBot", () => {
19571967 expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-opaque-1" ) ;
19581968 } ) ;
19591969
1960- it ( "toggles OC_MULTI buttons without routing through the generic callback message path" , async ( ) => {
1961- createTelegramBot ( { token : "tok" } ) ;
1962- const callbackHandler = getCallbackHandler ( ) ;
1963- await callbackHandler (
1964- makeCallbackRetryContext ( {
1965- id : "cbq-multi-toggle-1" ,
1966- data : "OC_MULTI|toggle|env|prod" ,
1967- messageId : 10 ,
1968- message : {
1969- business_connection_id : "biz-multi-1" ,
1970- reply_markup : {
1971- inline_keyboard : [ [ { text : "Prod" , callback_data : "OC_MULTI|toggle|env|prod" } ] ] ,
1970+ it . each ( [
1971+ { name : "delimited" , value : "env|prod" } ,
1972+ { name : "trailing-whitespace" , value : "env|prod " } ,
1973+ ] ) (
1974+ "toggles $name OC_MULTI buttons without routing through generic messages" ,
1975+ async ( { value } ) => {
1976+ const data = `OC_MULTI|toggle|${ value } ` ;
1977+ createTelegramBot ( { token : "tok" } ) ;
1978+ const callbackHandler = getCallbackHandler ( ) ;
1979+ await callbackHandler (
1980+ makeCallbackRetryContext ( {
1981+ id : "cbq-multi-toggle-1" ,
1982+ data,
1983+ messageId : 10 ,
1984+ message : {
1985+ business_connection_id : "biz-multi-1" ,
1986+ reply_markup : {
1987+ inline_keyboard : [ [ { text : "Prod" , callback_data : data } ] ] ,
1988+ } ,
19721989 } ,
1973- } ,
1974- } ) ,
1975- ) ;
1990+ } ) ,
1991+ ) ;
19761992
1977- expect ( editMessageReplyMarkupSpy ) . toHaveBeenCalledWith ( 1234 , 10 , {
1978- business_connection_id : "biz-multi-1" ,
1979- reply_markup : {
1980- inline_keyboard : [ [ { text : "✅ Prod" , callback_data : "OC_MULTI|toggle|env|prod" } ] ] ,
1981- } ,
1982- } ) ;
1983- expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
1984- expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-multi-toggle-1" ) ;
1985- } ) ;
1993+ expect ( editMessageReplyMarkupSpy ) . toHaveBeenCalledWith ( 1234 , 10 , {
1994+ business_connection_id : "biz-multi-1" ,
1995+ reply_markup : {
1996+ inline_keyboard : [ [ { text : "✅ Prod" , callback_data : data } ] ] ,
1997+ } ,
1998+ } ) ;
1999+ expect ( replySpy ) . not . toHaveBeenCalled ( ) ;
2000+ expect ( answerCallbackQuerySpy ) . toHaveBeenCalledWith ( "cbq-multi-toggle-1" ) ;
2001+ } ,
2002+ ) ;
19862003
19872004 it ( "submits OC_MULTI selections as a synthetic inbound message" , async ( ) => {
19882005 createTelegramBot ( { token : "tok" } ) ;
0 commit comments