File tree 4 files changed +28
-10
lines changed
4 files changed +28
-10
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @codebolt/codeboltjs" ,
3
- "version" : " 1.1.40 " ,
3
+ "version" : " 1.1.41 " ,
4
4
"description" : " " ,
5
5
"keywords" : [],
6
6
"author" : " " ,
Original file line number Diff line number Diff line change @@ -37,12 +37,18 @@ const cbchat = {
37
37
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
38
38
* @returns {EventEmitter } The event emitter used for emitting custom events.
39
39
*/
40
- userMessageListener : ( ) => {
40
+ onActionMessage : ( ) => {
41
41
if ( ! cbws . getWebsocket ) return ;
42
42
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
43
43
const response = JSON . parse ( data ) ;
44
44
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
+ } ) ;
46
52
}
47
53
} ) ;
48
54
return eventEmitter ;
Original file line number Diff line number Diff line change @@ -98,11 +98,23 @@ const cbcrawler = {
98
98
/**
99
99
* Initiates a crawl process.
100
100
*/
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
+
106
118
}
107
119
} ;
108
120
Original file line number Diff line number Diff line change @@ -22,10 +22,10 @@ class cbws {
22
22
private getUniqueConnectionId ( ) : string {
23
23
try {
24
24
let fileContents = fs . readFileSync ( './codebotagent.yml' , 'utf8' ) ;
25
- let data = yaml . load ( fileContents ) ;
25
+ let data : any = yaml . load ( fileContents ) ;
26
26
return data . uniqueConnectionId ;
27
27
} catch ( e ) {
28
- console . log ( e ) ;
28
+ console . error ( 'Unable to locate codebotagent.yml file.' ) ;
29
29
return '' ;
30
30
}
31
31
}
You can’t perform that action at this time.
0 commit comments