所以我是 IBM Watson 助手的新手,我想知道,当我为发送消息的当前用户初始化会话时,我应该将它存储在哪里,以及如何告诉 watson 例如在 user1 和 user2 的 session_id 之间有所不同?
现在我尝试在 nodejs 中使用全局变量,但正如我所说的那样,我无法在多个用户的会话之间产生差异。
const assistant = new WatsonAssistant({
username: process.env.WATSON_USERNAME,
password: process.env.WATSON_PASSWORD,
url: process.env.WATSON_URL,
version: process.env.WATSON_VERSION
});
exports.getMessage = body => new Promise(async (resolve, reject) => {
// Initializing session for current user
if(!global.session_id){
const createdSessionId = await assistant.createSession({
assistant_id: process.env.WATSON_ASSISTANT_ID
});
global.session_id = createdSessionId.session_id;
}
assistant.message(
{
workspace_id: process.env.WATSON_WORKSPACE_ID,
input: { text: body.input },
session_id: global.session_id,
assistant_id: process.env.WATSON_ASSISTANT_ID
},
function(err, response) {
if (err) {
console.log(err);
reject(err);
} else {
resolve(response);
}
}
);
});```
I would like to have session_id's of multiple users who have used my chatbot.