mardi 25 avril 2017

Calling processMessage() from bot.on('send')

I am writing tests for my bot using Jest, and I have the following code:

let bot;
let conn;
let index = 0;
let responses = [];
let expectedResponses = [];

beforeEach(() => {
    let connector = new builder.ConsoleConnector();
    bot = new builder.UniversalBot(connector);
    conn = connector;
});

test('test case 1 jeff', () => {
    bot.library(require('../dialogs/inputRecognizer').createLibrary());
    // the main dialog "/" should start "inputRecognizer:/"
    // as it can be seen [http://ift.tt/2p0Y2mV] the code below seems to be identical to the one shown in examples
    bot.dialog('/', [
        (session) => {
            session.beginDialog('inputRecognizer:/');
        }
    ]);

    basicMessages.forEach(o => {if (o.in) {expectedResponses.push(o.in)}});

    bot.on('send', function (message) {
        responses.push(message.text);
        index++;
        if (index < testMessages.length) {
            conn.processMessage(basicMessages[index].out);
        } else {
            expect(responses).toEqual(expectedResponses);
        }
    });

    conn.processMessage(basicMessages[0].out);
});

The code runs fine and inputs all my messages into the connector. However, the second message is treated as a new dialog, as are all the following messages. So what I get is the dialog starting over and over again.

I've looked into the BotFramework tests at GitHub and it looks like they're using a similar approach (trigger the first processMessage outside the 'send' event handler, and call the next ones from the handler).

How do I get processMessage to not restart my dialog every time? I assume it's a problem with my dialog, maybe?

My dialog code ("inputRecognizer:/"):

lib.dialog('/', [
    function (session) {
        // it always executes this part
        builder.Prompts.text(session,
            `Please type your inquiry!`);
    },
    (session, result) => {
        if (result.response) {
            // and it never gets to here

Aucun commentaire:

Enregistrer un commentaire