botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

node.js TypeError: choice.trim is not a function

Open mukeshps25 opened this issue 9 years ago • 1 comments

Please let me know what wrong with my code.

Web API call Result when the getOrderList function call :

[{"Country":"Germany","CompanyName":"Company1","OrderID":10285},{"Country":"Germany","CompanyName":"Company1","OrderID":10691},{"Country":"Germany","CompanyName":"Company1","OrderID":10418},{"Country":"Germany","CompanyName":"Company1","OrderID":10991},{"Country":"Germany","CompanyName":"Company1","OrderID":11021},{"Country":"Germany","CompanyName":"Company1","OrderID":10540},{"Country":"Germany","CompanyName":"Company1","OrderID":10527}]

bot Call :

bot.dialog('/Tree Node', [
        var checkTree = treeRoot.first(function (node) {
            return node.model.attributes.id === session.userData.profile.treeSelectdNodeId;
        });
        if(checkTree.hasChildren()) { 
            getTreeNode(session);
        } else { 
           session.beginDialog('/OrderList');
       }
]);

bot.dialog('/OrderList', [
    function (session, args) {
        getOrderList(session);
    },
    function (session, results) {
        //session.userData.profile.OrderID = results.response.entity;
        session.send("You entered order '%s'", results.response.entity);
        var ordStatus = false;
        var enterOrder = results.response.entity;
        if (gblOrderDataList.some(function (i) {
            return (new RegExp('\\b' + i + '\\b')).test(enterOrder);
        })) {
            ordStatus = true;
        }
        if (ordStatus) {
            session.userData.profile.OrderID = results.response.entity;
            session.send("You entered '%s'", results.response.entity);
            //session.replaceDialog('/Tree Node');
        } else {
            session.replaceDialog('/OrderList', {reprompt: true});
        }  
    }
]);
var gblOrderDataList;
function getOrderList(session) { 
    var request     = require("request");
    var url = 'http://localhost:8084/api/fetch/' + session.userData.profile.userToken + '/0/System/' + "/" + session.userData.profile.country+'/'+session.userData.profile.company;
    request(url, function (error, response, body)
    {
        if (!error && response.statusCode == 200) {
            displaygetOrderListAnswer(body, session);
        } else {
            session.send("There is an error with get order list request...." );
            session.beginDialog('/menu');
        }
    });
}

function displaygetOrderListAnswer(resData, session) { 
    if(resData) {
        var jsondata = parseJson(resData);
        var reportsArray = [];
        for (var i = 0; i < jsondata.length; i++) {
            if(jsondata[i].OrderID !='' && jsondata[i].OrderID != undefined) { 
                reportsArray.push(jsondata[i].OrderID);
            }
        }
        if(reportsArray.length > 0 ) { 
            gblOrderDataList = reportsArray;
            builder.Prompts.choice(session, "Please select the " + session.userData.profile.treeSelectdNodeTitle + " to view?", reportsArray);
        } else {
            session.send('Something went wrong. You can use the back or top command.');
        }
    } else {
        session.send("There is an error with order list answer....");
    }
}

Skype Bot see options like

Please select the Navigate the hierarchy to view?

  1. 10285
  2. 10691
  3. 10418
  4. 10991
  5. 11021

if User select the 1 choice on skype bot then its showing the below error. Not able to track but I got the same issue in the previously when I started working with skype bot.

/home/node_modules/promise/lib/done.js:10
      throw err;
      ^

TypeError: choice.trim is not a function
    at /home/node_modules/botbuilder/lib/dialogs/EntityRecognizer.js:158:32
    at Array.forEach (native)
    at Function.EntityRecognizer.findAllMatches (/home/node_modules/botbuilder/lib/dialogs/EntityRecognizer.js:156:49)
    at Function.EntityRecognizer.findBestMatch (/home/node_modules/botbuilder/lib/dialogs/EntityRecognizer.js:143:40)
    at findChoice (/home/node_modules/botbuilder/lib/dialogs/Prompts.js:38:50)
    at SimplePromptRecognizer.recognize (/home/node_modules/botbuilder/lib/dialogs/Prompts.js:84:28)
    at Prompts.recognize (/home/node_modules/botbuilder/lib/dialogs/Prompts.js:147:36)

mukeshps25 avatar Jan 10 '17 09:01 mukeshps25

After playing with the code found one solution....

reportsArray.push(jsondata[i].OrderID.toString());

mukeshps25 avatar Jan 16 '17 07:01 mukeshps25