i'm trying to write a funny chatbot in node.js & socket.io. there is a deley of 5 second in bot reply. this is working good but when more then one user start chat with a bot there socket instances override to last one. take a look into the code
exports.newMessage = function(data, ack){
var socket = this
console.log(`newMessage listening`,data);
botReply = looking4bot(data.message)
setTimeout( ()=> {
// if socket reconnected then find correct client
if(client = users[data.to_user] )
client.emit("newMessage", botReply)
}, 5000)
}
i carefully read http://javascript.info/bind but did't help. i think bind is not useful here because whenever second user start chat before first's timeout, function rebind and intances override. anyone help me pls to slove issue