由用户退出CommandDialog

我试图find一种方式退出CommandDialog对话框时,用户使用backcancel或以其他方式改变主意。

 var startCommands = new builder.CommandDialog(); bot.add('/', [ function (session, results) { session.send('Hello %s', session.userData.name); // starting a dialog based on CommandDialog session.beginDialog('/begin'); }, function (session, results) { // This is where I want to be when dialog cancel of back is initiated by a user inside /begin session.send("you are back at the main dialog, start finshing process") session.beginDialog('/finish'); } ]); // defining a dialog for CommandDialog class bot.add('/begin', startCommands) bot.add('/finish', finishCommands) startCommands.matches('yo', [ function (session) { session.send('yo-yo'); } ]); startCommands.matches('tu', [ function (session) { session.send('tu-tu'); } ]); startCommands.matches('.*', [ function (session) { session.send('any-any'); session.endDialog(); } ]); 

要退出对话框,CommandDialog或其他方法, triggerAction在调用session.endConversation()的对话框处理程序上使用triggerAction

例如,这里是一个exit对话框,当用户发送消息exitquit时结束对话。

 bot.dialog('exit', function (session) { session.endConversation('Goodbye!'); }).triggerAction({ matches: /(quit|exit)/i });