私はSkypeボットアプリに取り組んでいます。ツリーモデルからのノードの読み取りに問題があります。ツリーモデルの例は子ノードに従いますが、私のノードにはシステムが読み取る差分タブがあります。
XML の例 -
<?xml version="1.0" encoding="UTF-8" ?>
<rootmenu id="1" title="menu" description="What scenario would you like to run?">
<MenuOption id="1.1" title="Company Data" response="You entered company data" description="What action would you like to perform">
<HierarchyMenuItem id="1.1.1.1" title="Select new data " response="You entered select new filter">
<action>Filter</action>
</HierarchyMenuItem>
<HierarchyMenuItem id="1.1.1.2" title="Navigate node" response="You entered select node">
<action description="Current Filter is ">Hierarchy</action>
<HierarchyLevel level="1" name="One" navigateHierarchy="true">
<action>RootAction</action>
<Option title="Select a Country">
<OptionChoices id="1" title="One1" refNode="ForOne1" />
<OptionChoices id="2" title="One2" refNode="ForOne2" />
<OptionChoices id="3" title="One3" refNode="ForOne3" />
<OptionChoices id="4" title="One4" refNode="ForOne4" />
</Option>
</HierarchyLevel>
</HierarchyMenuItem>
</MenuOption>
<MenuOption id="1.2" title="Adhoc Data">
<Option>
<OptionChoices id="1" title="Ad1" refNode="ForAdOne1" />
<OptionChoices id="2" title="Ad2" refNode="ForAdOne2" />
<OptionChoices id="3" title="Ad3" refNode="ForAdOne3" />
<OptionChoices id="4" title="Ad4" refNode="ForAdOne4" />
</Option>
</MenuOption>
<MenuOption id="1.3" title="(quit)">
</MenuOption>
</rootmenu>
サーバーからxmlを読み取ります-
function getXMLData(callback) {
var request = require('request');
var DOMParser = require('xmldom').DOMParser;
var simpleconvertxml = require('simpleconvert-xml');
request('http://demo.in/RefactoredXML.xml', function (error, response, body) {
if (!error && response.statusCode == 200) {
var xmlnode = new DOMParser().parseFromString([body].join('\n'), 'text/xml');
var myNumber = simpleconvertxml.getXMLAsObj(xmlnode);
treeRoot = tree.parse(myNumber.rootmenu);
callback(treeRoot);
}
})
}
私の最初のボット呼び出し
bot.dialog('/menu', [
function (session, args) {
getXMLData(function (treeRoot) {
//session.send('node place:'+treeRoot.model.title);
var firstChild = [];
for (var i = 0; i < treeRoot.model.MenuOption.length; i++) {
if(treeRoot.model.MenuOption[i].title !='' && treeRoot.model.MenuOption[i].title != undefined && treeRoot.model.MenuOption[i].title != null) {
firstChild.push(treeRoot.model.MenuOption[i].title);
}
}
if(firstChild.length > 0) {
builder.Prompts.choice(session, treeRoot.model.description,firstChild );
// it shows builder.Prompts.choice(session, "What scenario would you like to run? ", "company data|adhoc data|(quit)");
} else {
session.send('Something went wrong. You can use the back or top command.');
}
});
},
function (session, results) {
if (results.response && results.response.entity != '(quit)') {
session.userData.profile.treeSelectdNodeTitle = results.response.entity;
getXMLData(function (treeRoot) {
for (var i = 0; i < treeRoot.model.MenuOption.length; i++) {
if(treeRoot.model.MenuOption[i].title == session.userData.profile.treeSelectdNodeTitle) {
session.userData.profile.treeSelectdNodeId = treeRoot.model.MenuOption[i].id;
session.userData.profile.treeSelectdResponse = treeRoot.model.MenuOption[i].response;
}
}
session.send('resp ' + session.userData.profile.treeSelectdResponse);
if(treeRoot.hasChildren()) {
session.send('in the children');
session.beginDialog('/get Tree Node');
} else {
session.send('in the title');
session.beginDialog('/'+ treeRoot.model.title);
}
});
} else {
// Exit the menu
session.endDialog();
}
},
function (session, results) {
// The menu runs a loop until the user chooses to (quit).
session.replaceDialog('/menu');
}
]).reloadAction('reloadMenu', null, {matches: /^menu|show menu|top|top menu/i});
メニュー ダイアログ コールは 1.company data 2. adhoc data 3. (quit) を表示する必要がありますが、1.company data 2.adhoc data のみを表示し、ユーザーが Company Data として 1 つのオプションを選択するとメニューに問題が発生します。 treeRoot.hasChildren() 条件。
bot.dialog('/get Tree Node', [
function(session,agrs) {
getTreeNode(session);
}
]);
function getTreeNode(session) {
session.send("in tree "+ session.userData.profile.treeSelectdNodeId);
getXMLData(function(treeRoot) {
var nextLevel = treeRoot.first(function (node) {
return node.model.id === session.userData.profile.treeSelectdNodeId;
});
session.send('selected title '+ nextLevel.model.HierarchyMenuItem[0].title);
/* var secondListChild = [];
for(var i = 0; i < nextLevel.model.HierarchyMenuItem.length; i++) {
if(nextLevel.model.HierarchyMenuItem[i].title !='' && nextLevel.model.HierarchyMenuItem[i].title != undefined && nextLevel.model.HierarchyMenuItem[i].title != null) {
secondListChild.push(nextLevel.model.HierarchyMenuItem[i].title);
}
}
if(secondListChild.length > 0) {
builder.Prompts.choice(session, nextLevel.model.description,secondListChild);
} else {
session.send('Something went wrong. You can use the back or top command.');
} */
});
}
getTreeNode の問題は session.send('selected title'+ nextLevel.model.HierarchyMenuItem[0].title); です。^ TypeError: 未定義のプロパティ 'モデル' を読み取れません