node-telegram-bot-api
node-telegram-bot-api copied to clipboard
best practice for manage user concurrency
Hello everybody, I'm new to telegram and to node.js. I'm doing a bot in which a user can notify and event that will be store in a mongo database.Every user talk individually with the bot. I use bot.ontext and bot.on('message') for get user message but if more than what user is using the bot will response to any of them. For example here after I get a location I want to add to the alert(a notify of some event) the event.But when the bot get the location, the bot.once('message') will listen any message sent from any user.
bot.on("location", function (msg) {
bot.sendMessage(msg.chat.id,"Location get.Insert the event that has occured", alert2_kb).then(() =>
{
var longitude = msg.location.longitude;
var latitude = msg.location.latitude;
var Alert = require("./models/alert");
alert = new Alert({date:new Date(),timestamp: Date.now(), chatId: msg.chat.id, latitude: latitude, longitude: longitude});
bot.once("message", function(answer) {
switch(answer.text){
case "Problem 1":{
alert.type = 1;
break;
}
case "Problem 2":{
alert.type = 2;
break;
}case "Problem 3":{
alert.type = 3;
break;
}
default:break;
}
if(alert.type){
alert.save(function (err, alert) {
if (err) throw err
console.log("Saved to DB");
});
bot.sendMessage(receiver, "Alert gets successfully.", start_keyboard);
}
})
})
}
})
I have the same problem! How can we listen to a specific user just like we send a message to a specific one referring to their message.chat.id?
@pani94 Your answer is not clear for me, you should send lots of messages to a list of users that have subscribed to your bot?
@pani94 Could you fix the broken markdown (code) in your issue/question?