-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
51 lines (40 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { io, Socket } from 'socket.io-client';
class UCI {
socket: Socket | undefined;
msgReceiveCb: any;
session: any;
constructor(URL: string, socketOptions: any, onRecieveCallback: any) {
this.socket = io(URL, socketOptions);
this.msgReceiveCb = onRecieveCallback;
this.socket.connect();
this.socket.on("botResponse", this.handleMessage);
this.socket.on("session", this.handleSocketSession);
}
handleMessage = (message: any) => {
//ReceiveCallback to be used here
console.log(message);
this.msgReceiveCb(message);
};
handleSocketSession = (session:any) => {
this.session = session;
};
onDisconnect = () => {
this.socket?.disconnect()
}
sendMessage = ({ text, to, from, optional }: any) => {
this.socket?.emit("botRequest", {
content: {
text,
to,
appId: optional?.appId,
channel: optional?.channel,
from,
userId: this.session.userID,
context: null,
accessToken: null,
},
to,
});
};
}
export { UCI };