0

我正在 wit.ai 中尝试不同的故事。这是我想报告丢失的信用卡的一种情况。当用户说他丢失了信用卡时,机器人必须分两步询问他的 SSN,然后是母亲/娘家姓,然后它必须阻止信用卡。这是申请链接: https ://wit.ai/Nayana-Manchi/CreditCardApp/stories/f7d77d9e-e993-428f-a75e-2e86f0e73cb3

问题:

  1. 在我发现的实体列表中,当它调用动作时,它只需要实体列表中的第二个输入(即本例中的母亲姓名,SSN 为空)。我在 JavaScript 代码中放置了一些日志以查找实体列表。对于这些场景,我是否也需要遵循基于插槽的方法?

  2. 基于插槽的方法在这里不适合,因为用户不知道什么是安全问题。

  3. 仅当(有/没有)选项存在时,才在操作选项卡中。请解释一下它的用法。如果我在那里设置所需的实体(在这种情况下:SSN 和母亲姓名),机器人会像循环一样连续询问 SSN。

代码类似于快速入门示例,但对读取实体进行了一些更改。结果在 node-wit 终端中,并在 javascript 中添加了记录的消息

4

1 回答 1

0

您应该在send Action中保存属于同一会话的实体。

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);
});

于 2016-09-26T17:36:07.930 回答