node.js - I am trying to echo the changed name on the console.. but the program quits as in when I enter the new name -
i using textbot echo name user enters , added option change name of user using set name
command, program takes new name , won't print it. wondering what's wrong?
here's code
var builder = require('botbuilder'); var hellobot = new builder.textbot(); hellobot.add('/', new builder.commanddialog() .matches('^set name', builder.dialogaction.begindialog('/profile')) .matches('^quit', builder.dialogaction.enddialog()) .ondefault([ function (session, args, next) { if (!session.userdata.name) { session.begindialog('/profile'); } else { console.log('in else part..'); next(); } }, function (session, results) { session.send('hello %s!', session.userdata.name); } ])); hellobot.add('/profile', [ function (session) { if (session.userdata.name) { builder.prompts.text(session, 'what change to?'); console.log('setting name..'); } else { builder.prompts.text(session, 'hi! name?'); } }, function (session, results) { session.userdata.name = results.response; session.enddialog(); } ]); hellobot.listenstdin();
the output should like:
hi hi! name? james hello james! set name change to? bond
the program quits here while expected output hello bond!
the problem .ondefault never called because root dialog matched "set name" condition.
try code (uses updated version of botbuilder):
var builder = require('botbuilder'); var connector = new builder.consoleconnector().listen(); var bot = new builder.universalbot(connector); var intents = new builder.intentdialog(); bot.dialog('/', intents); intents.matches(/^set name/i, [ function (session) { session.begindialog('/profile'); }, function (session, results) { session.send('hello %s!', session.userdata.name); } ]); intents.ondefault([ function (session, args, next) { if (!session.userdata.name) { session.begindialog('/profile'); } else { next(); } }, function (session, results) { session.send('hello %s!', session.userdata.name); } ]); bot.dialog('/profile', [ function (session) { if (session.userdata.name) { builder.prompts.text(session, 'what change to?'); } else { builder.prompts.text(session, 'hi! name?'); } }, function (session, results) { session.userdata.name = results.response; session.enddialog(); } ]);
Comments
Post a Comment