Skip to content

Commit 1be54f8

Browse files
changes
1 parent fd622a5 commit 1be54f8

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.40",
3+
"version": "1.1.41",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/modules/chat.ts

+8-2
Original file line numberDiff line numberDiff 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;

src/modules/crawler.ts

+17-5
Original file line numberDiff line numberDiff 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

src/modules/websocket.ts

+2-2
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)