@@ -75,7 +75,6 @@ type QrCommandContext = {
7575} ;
7676
7777type QrChannelSender = {
78- resolveSend : ( api : OpenClawPluginApi ) => QrSendFn | undefined ;
7978 createOpts : ( params : {
8079 ctx : QrCommandContext ;
8180 qrFilePath : string ;
@@ -84,57 +83,45 @@ type QrChannelSender = {
8483 } ) => Record < string , unknown > ;
8584} ;
8685
87- type QrSendFn = ( to : string , text : string , opts : Record < string , unknown > ) => Promise < unknown > ;
88-
89- function coerceQrSend ( send : unknown ) : QrSendFn | undefined {
90- return typeof send === "function" ? ( send as QrSendFn ) : undefined ;
91- }
92-
9386const QR_CHANNEL_SENDERS : Record < string , QrChannelSender > = {
9487 telegram : {
95- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. telegram ?. sendMessageTelegram ) ,
9688 createOpts : ( { ctx, qrFilePath, mediaLocalRoots, accountId } ) => ( {
9789 mediaUrl : qrFilePath ,
9890 mediaLocalRoots,
99- ...( typeof ctx . messageThreadId === "number" ? { messageThreadId : ctx . messageThreadId } : { } ) ,
91+ ...( ctx . messageThreadId != null ? { threadId : ctx . messageThreadId } : { } ) ,
10092 ...( accountId ? { accountId } : { } ) ,
10193 } ) ,
10294 } ,
10395 discord : {
104- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. discord ?. sendMessageDiscord ) ,
10596 createOpts : ( { qrFilePath, mediaLocalRoots, accountId } ) => ( {
10697 mediaUrl : qrFilePath ,
10798 mediaLocalRoots,
10899 ...( accountId ? { accountId } : { } ) ,
109100 } ) ,
110101 } ,
111102 slack : {
112- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. slack ?. sendMessageSlack ) ,
113103 createOpts : ( { ctx, qrFilePath, mediaLocalRoots, accountId } ) => ( {
114104 mediaUrl : qrFilePath ,
115105 mediaLocalRoots,
116- ...( ctx . messageThreadId != null ? { threadTs : String ( ctx . messageThreadId ) } : { } ) ,
106+ ...( ctx . messageThreadId != null ? { threadId : String ( ctx . messageThreadId ) } : { } ) ,
117107 ...( accountId ? { accountId } : { } ) ,
118108 } ) ,
119109 } ,
120110 signal : {
121- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. signal ?. sendMessageSignal ) ,
122111 createOpts : ( { qrFilePath, mediaLocalRoots, accountId } ) => ( {
123112 mediaUrl : qrFilePath ,
124113 mediaLocalRoots,
125114 ...( accountId ? { accountId } : { } ) ,
126115 } ) ,
127116 } ,
128117 imessage : {
129- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. imessage ?. sendMessageIMessage ) ,
130118 createOpts : ( { qrFilePath, mediaLocalRoots, accountId } ) => ( {
131119 mediaUrl : qrFilePath ,
132120 mediaLocalRoots,
133121 ...( accountId ? { accountId } : { } ) ,
134122 } ) ,
135123 } ,
136124 whatsapp : {
137- resolveSend : ( api ) => coerceQrSend ( api . runtime ?. channel ?. whatsapp ?. sendMessageWhatsApp ) ,
138125 createOpts : ( { qrFilePath, mediaLocalRoots, accountId } ) => ( {
139126 verbose : false ,
140127 mediaUrl : qrFilePath ,
@@ -518,20 +505,22 @@ async function sendQrPngToSupportedChannel(params: {
518505 if ( ! sender ) {
519506 return false ;
520507 }
521- const send = sender . resolveSend ( params . api ) ;
508+ const adapter = await params . api . runtime . channel . outbound . loadAdapter ( params . ctx . channel ) ;
509+ const send = adapter ?. sendMedia ;
522510 if ( ! send ) {
523511 return false ;
524512 }
525- await send (
526- params . target ,
527- params . caption ,
528- sender . createOpts ( {
513+ await send ( {
514+ cfg : params . api . config ,
515+ to : params . target ,
516+ text : params . caption ,
517+ ...sender . createOpts ( {
529518 ctx : params . ctx ,
530519 qrFilePath : params . qrFilePath ,
531520 mediaLocalRoots,
532521 accountId,
533522 } ) ,
534- ) ;
523+ } ) ;
535524 return true ;
536525}
537526
@@ -769,18 +758,20 @@ export default definePluginEntry({
769758 channelKeys . join ( "," ) || "none"
770759 } `,
771760 ) ;
772- const send = api . runtime ?. channel ?. telegram ?. sendMessageTelegram ;
761+ const adapter = await api . runtime . channel . outbound . loadAdapter ( "telegram" ) ;
762+ const send = adapter ?. sendText ;
773763 if ( ! send ) {
774764 throw new Error (
775765 `telegram runtime unavailable (runtime keys: ${ runtimeKeys . join ( "," ) } ; channel keys: ${ channelKeys . join (
776766 "," ,
777767 ) } )`,
778768 ) ;
779769 }
780- await send ( target , formatSetupInstructions ( payload . expiresAtMs ) , {
781- ...( typeof ctx . messageThreadId === "number"
782- ? { messageThreadId : ctx . messageThreadId }
783- : { } ) ,
770+ await send ( {
771+ cfg : api . config ,
772+ to : target ,
773+ text : formatSetupInstructions ( payload . expiresAtMs ) ,
774+ ...( ctx . messageThreadId != null ? { threadId : ctx . messageThreadId } : { } ) ,
784775 ...( ctx . accountId ? { accountId : ctx . accountId } : { } ) ,
785776 } ) ;
786777 api . logger . info ?.(
0 commit comments