-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (43 loc) · 1.5 KB
/
index.js
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
let responder = require('./savio/responder');
function Savio(configurations){
this.type = configurations.type;
this.chatFlow = configurations.chatFlow;
this.databaseModel = configurations.databaseModel;
this.dbService = configurations.dbService;
this.welcomeFlow = configurations.welcomeFlow;
this.socket = configurations.socket
this.getMessage = function(text, from){
return new Promise((resolve, reject)=>{
return this.dbService.getUser(from).then((userDetails)=>{
if(!userDetails){
userDetails = {
from: from
}
}
return responder.generateResponseMessage(text, userDetails, this.chatFlow, this.dbService, this.welcomeFlow).then((resp)=>{
return resolve(resp)
},(err)=>{
return reject(err)
});
}, (error)=>{
return reject(error)
})
})
}
if(this.socket){
let self = this;
this.socket.on('connection', (sock)=>{
sock.on('chat-message', function(data){
self.getMessage(data.text, data.from).then((resp)=>{
sock.emit("chat-message", resp[0])
}, (error)=>{
console.log("Err", error)
throw error;
})
})
})
}
}
Savio.prototype.serviceMessage = function(options){
}
module.exports = Savio;