@@ -21,22 +21,55 @@ export class WebChannel extends BaseChannel {
2121
2222 async prepareMessage ( req : Request , res : Response ) { }
2323
24- public async sendMessageToUser ( { userId, text, type } : {
24+ public async sendMessageToUser ( { userId, text, type, channelData } : {
2525 type ?: string ;
2626 userId : string ;
2727 text : string ;
28+ channelData : any ;
2829 } ) {
2930 try {
30- if ( App . io ) {
31+ let result = { userId , messages : text || '' , template : { } } ;
3132
32- App . io . to ( userId ) . emit (
33- type || SOCKET_EVENTS . MESSAGE ,
34- { userId, message : text } ) ;
33+ if ( channelData ) {
34+ result . template = {
35+ data : channelData . extendData ,
36+ type : channelData . type ,
37+ }
38+ }
39+ console . log ( 'result: ' + JSON . stringify ( result ) ) ;
40+ if ( App . io ) {
41+ App . io . to ( userId ) . emit ( type || SOCKET_EVENTS . MESSAGE , result ) ;
3542 }
3643 } catch ( e ) {
3744 logger . info (
3845 `[WEB] Bot send message to User failed - Error: ${ e . message } ` ,
3946 )
4047 }
4148 }
49+
50+ // async detectTemplate(channelData: any) {
51+ // let result = null;
52+ // if (!channelData) return result;
53+
54+ // switch (channelData.type) {
55+ // case 'list-button':
56+ // result = {
57+ // data: channelData.extendData,
58+ // type: channelData.type,
59+ // }
60+ // break;
61+ // case 'list-card':
62+ // result = {
63+ // data: channelData.extendData,
64+ // type: channelData.type,
65+ // }
66+ // break;
67+ // default:
68+ // logger.info(
69+ // `[WEB] channel web does not support type ${channelData.type}`,
70+ // )
71+ // break;
72+ // }
73+ // return result;
74+ // }
4275}
0 commit comments