0

I am trying different stories in wit.ai. Here is one scenario where I want to report lost credit card. When user says he lost credit card, bot has to ask his SSN followed by mother/maiden name in 2 steps and then it has to block the card. Here is the application link: https://wit.ai/Nayana-Manchi/CreditCardApp/stories/f7d77d9e-e993-428f-a75e-2e86f0e73cb3

Issues:

  1. In the entites list I found that, it takes only 2nd input (i.e. mother name in this case, SSN is null) in the entities list when it calls action. I put some logs in JavaScript code to find the entities list. Do I need to follow slot based approach for these scenarios as well?

  2. Slot based approach is not suitable here, as the user does not know what are the security questions.

  3. In actions tab only if (has/doesn’t have) options are there. Kindly explain its usage. If I set required entities (in this case: SSN and mother name) there, bot asks for SSN continuously like a loop.

Code is similar to quickstart sample with some changes to read entities.Result in node-wit terminal with logged messages added in javascript

Nayana M
  • 65
  • 7

1 Answers1

0

You should save enetities belongs to same session in 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 it in custom actions

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

To stop it from re running your actions, delete 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);
});
Ashes Vats
  • 136
  • 1
  • 4