2016-07-27 1 views
0

Может быть, я глуп, но я действительно не понимаю, как читать node.js version of Microsoft's bot framework sdk. Я пытаюсь выяснить, как использовать beginDialogAction() или endConversationAction() в ConsoleConnector bot. В документации говорится, что он регистрирует действие при запуске, но не упоминает, как его запускать. Я хочу использовать идею о том, что он может добавить диалог в середине стоп-кадра вне нормального потока.node.js bot framework universalbot beginDialogAction используется?

Я сожалею, что не могу предоставить код, но я могу дать это ...

var connector = new builder.ConsoleConnector().listen(); 
var connector = new builder.ConsoleConnector().listen(); 
var bot = new builder.UniversalBot(connector); 

bot.dialog('/', [ 
    function(session) { 
     builder.Prompts.text(session, "blah blah blah?"); 
    }, 
    function(session, results) { 
     // ... 

     session.beginDialog('/foo'); 
     session.endDialog(); 
    } 
]); 

bot.dialog('/foo', [ 
    function(session, args) { 
     // ... 
    }, 
    function(session, results) { 
     // ... 
     session.endDialog(); 
    } 
]); 

bot.use({ botbuilder: function(session, next) { 

    // CALL THE ACTION 'bar' HERE TO ADD '/help' to the callstack 

    // ... 
    next(); 
}}); 

bot.beginDialogAction('bar', '/help'); 

bot.dialog('/help', [ 
    function(session, args) { 
     // ... 
    }, 
    function(session, results) { 
     // ... 
     session.endDialog(); 
    } 
]); 

ответ

3

, как я понимаю, и использовать его: действие что-то явно, что вы можете вызывать из вашего диалога поток для запуска других диалогов + параметров.

В качестве примера здесь является нормальным потоком для бота, вызванный диалог ввода:

bot.dialog('/', new builder.IntentDialog() 
.matches(/^command1/i, '/command1') 
.matches(/command2/i, '/command2') 
.onDefault(..)); 

bot.dialog('/command1', [ 
    function (session) { 
     session.send('Hello.'); 
    } 
]); 

Например, вы можете использовать диалоговые действия, чтобы вызвать действие непосредственно вместо маршрутизации функции:

.onDefault(builder.DialogAction.send("Hello World!")) 

Что касается beginDialogAction(), подумайте об этом как о кресте между обоими. Рассмотрим следующий пример карточки:

// An actions is just a normal card of any type that 
// features a dialogAction with the respective parameters. 
bot.dialog('/Action', [ 
    function (session) { 
     // Create a new message. Note that cards are managed as attachments 
     // that each channel can interpret as they see fit. Remember that some 
     // channels are text only, so they will have to adapt. 
     var msg = new builder.Message(session) 
      .textFormat(builder.TextFormat.xml) 
      .attachments([ 
       // This is the actual hero card. For each card you can add the 
       // specific options like title, text and so on. 
       new builder.HeroCard(session) 
        .title("Hero Card") 
        .subtitle("Microsoft Bot Framework") 
        .text("Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.") 
        .images([ 
         builder.CardImage.create(session, "https://bot-framework.azureedge.net/bot-icons-v1/bot-framework-default-7.png") 
        ]) 
        .buttons([ 
         builder.CardAction.dialogAction(session, "News", "https://blog.botframework.com/", "Get news") 
        ]) 
      ]); 

     // Send the message to the user and end the dialog 
     session.send(msg); 
     session.endDialog(); 
    } 
]); 

Обратите внимание, что эта карта запускает акцию под названием «Новости» с параметром «https://blog.botframework.com/» с помощью кнопки. Подумайте об этом как о функции, вызываемой в вашем диалоговом окне, нажав кнопку на карте. Теперь, чтобы определить эту функцию, мы делаем:

// An action is essentially a card calling a global dialog method 
// with respective parameters. So instead of using choice prompts 
// or a similar waterfall approach, you can link to separate 
// dialogs. 
// The dialog action will route the action command to a dialog. 
bot.beginDialogAction('News', '/News'); 

// Create the dialog itself. 
bot.dialog('/News', [ 
    function (session, args) { 
     session.endDialog("Loading news from: " + args.data); 
    } 
]); 

Так с этим мы можем отобразить общие новости диалогов на основе параметра мы передаем, вызванный другими диалогами.

Имеет смысл?

 Смежные вопросы

  • Нет связанных вопросов^_^