File tree Expand file tree Collapse file tree 4 files changed +28
-10
lines changed Expand file tree Collapse file tree 4 files changed +28
-10
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @codebolt/codeboltjs" ,
3- "version" : " 1.1.40 " ,
3+ "version" : " 1.1.41 " ,
44 "description" : " " ,
55 "keywords" : [],
66 "author" : " " ,
Original file line number Diff line number Diff line change @@ -37,12 +37,18 @@ const cbchat = {
3737 * Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
3838 * @returns {EventEmitter } The event emitter used for emitting custom events.
3939 */
40- userMessageListener : ( ) => {
40+ onActionMessage : ( ) => {
4141 if ( ! cbws . getWebsocket ) return ;
4242 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
4343 const response = JSON . parse ( data ) ;
4444 if ( response . type === "messageResponse" ) {
45- eventEmitter . emit ( "userMessage" , response . response ) ;
45+ // Pass a callback function as an argument to the emit method
46+ eventEmitter . emit ( "userMessage" , response , ( message : string ) => {
47+ console . log ( "Callback function invoked with message:" , message ) ;
48+ cbws . getWebsocket . send ( JSON . stringify ( {
49+ "type" : "processStoped"
50+ } ) ) ;
51+ } ) ;
4652 }
4753 } ) ;
4854 return eventEmitter ;
Original file line number Diff line number Diff line change @@ -98,11 +98,23 @@ const cbcrawler = {
9898 /**
9999 * Initiates a crawl process.
100100 */
101- crawl : ( ) => {
102- cbws . getWebsocket . send ( JSON . stringify ( {
103- "type" : "crawlerEvent" ,
104- action : 'crawl'
105- } ) ) ;
101+ crawl : ( query :string ) => {
102+ return new Promise ( ( resolve , reject ) => {
103+ cbws . getWebsocket . send ( JSON . stringify ( {
104+ "type" : "crawlerEvent" ,
105+ "action" : 'crawl' ,
106+ "message" :{
107+ query
108+ }
109+ } ) ) ;
110+ cbws . getWebsocket . on ( 'message' , ( data : string ) => {
111+ const response = JSON . parse ( data ) ;
112+ if ( response . type === "crawlResponse" ) {
113+ resolve ( response ) ; // Resolve the Promise with the response data
114+ }
115+ } ) ;
116+ } ) ;
117+
106118 }
107119} ;
108120
Original file line number Diff line number Diff line change @@ -22,10 +22,10 @@ class cbws {
2222 private getUniqueConnectionId ( ) : string {
2323 try {
2424 let fileContents = fs . readFileSync ( './codebotagent.yml' , 'utf8' ) ;
25- let data = yaml . load ( fileContents ) ;
25+ let data : any = yaml . load ( fileContents ) ;
2626 return data . uniqueConnectionId ;
2727 } catch ( e ) {
28- console . log ( e ) ;
28+ console . error ( 'Unable to locate codebotagent.yml file.' ) ;
2929 return '' ;
3030 }
3131 }
You can’t perform that action at this time.
0 commit comments