我在wit.ai尝试不同的故事。这是我想要报告丢失的信用卡的一种情况。当用户说他丢失了信用卡时,机器人必须分两步询问他的SSN,然后是母亲/婚前姓,然后它必须阻止该卡。这是应用程序链接: https://wit.ai/Nayana-Manchi/CreditCardApp/stories/f7d77d9e-e993-428f-a75e-2e86f0e73cb3
的问题:
答案 0 :(得分:0)
您应该在发送操作中保存属于同一会话的enetities。
send(request, response) {
const {sessionId, context, entities} = request;
const {text, quickreplies} = response;
const motherName = userSession[sessionId].fbid;
const motherName = firstEntityValue(entities, 'mother_name');
const SSN = firstEntityValue(entities, 'SSN');
// set context in user sessions to used in actions
// act as merge operation of old wit.ai api
if (motherName && SSN) {
sessions[sessionId].context.motherName = firstEntityValue(entities, 'mother_name');
sessions[sessionId].context.SSN = firstEntityValue(entities, 'SSN');
}
return new Promise(function (resolve, reject) {
console.log("Sending.. " ,text);
resolve();
});
},
中使用它
//to use saved entities from customAction
findCreditCard({sessionId, context, text, entities}) {
const SSN = sessions[sessionId].context.SSN;
const motherName = sessions[sessionId].context.motherName;
return new Promise(function (resolve, reject) {
// custom action code
//if everything gets completed then set context.done=true
if(completed) context.done=true
resolve(context);
});
});
要阻止它重新开始操作,请删除conext
wit.runActions(
sessionId,
text, // the user's message
sessions[sessionId].context // the user's current session state
).then((context) => {
console.log('Wit Bot haS completed its action', context);
// this will clear the session data
if (context['done']) {
console.log("clearing session data");
delete sessions[sessionId];
}
else {
console.log("updating session data");
// Updating the user's current session state
sessions[sessionId].context = context;
}
}).catch((err) => {
console.log('Oops! Got an error from Wit: ', err.stack || err);
});