我使用Microsoft Bot Framework在NodeJS中构建了一个bot,并将其部署在远程服务器上。我使用Bot-Emulator和ngrok从本地机器连接到bot,以接收响应。当我同时从两台独立的机器连接到机器人时,状态数据被覆盖,我得到不同ID的相同响应。 我试图使用UUID生成一个随机ID来区分对话,并尝试分别为不同的会话存储userID,但它对我不起作用。 有没有办法让机器人将每个实例视为一个单独的会话,或者只是不覆盖用户数据并将其单独存储,以便它可以为我们提供正确的查询响应?非常感谢。
bot.dialog('/employee', [
function (session) {
session.send("Welcome to the information portal.");
builder.Prompts.text(session, "Please provide the Network ID");
console.log(session.message.address.conversation.id);
},
function (session, results) {
//console.log(sessionid);
session.userData.employeeID = results.response;
session.endDialog("What information would you like for the employee?");
console.log(session.message.address.conversation.id);
}
])
bot.dialog('/email', [
function (session) {
const https = require("https");
const url =
"https://**********" + session.userData.employeeID;
https.get(url, res => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
console.log(
`${body[0]['****]} is working in ${body[0]['****']}.`,
);
session.send(`${body[0]['****']}'s email ID is ${body[0]['****']}.`);
console.log(session.message.address.conversation.id);
console.log(session.userData.employeeID);
console.log(session.userData);
var msg = `I hope your query was fulfilled. Thank you.`;
session.endConversation(msg);
});
});
}
])