palindromed / Bot-HandOff

MIT License
103 stars 79 forks source link

(Bug) Messages of non 'message' type are ignored in the middleware #19

Closed microsoftly closed 7 years ago

microsoftly commented 7 years ago

version 0.1.7

Bug: messages of non 'message' type never get past the handoff middleware

expected behavior: messages of non 'message' reach user defined middleware or dialogs.

code to recreate:

expected behavior: bot responds with 'received non standard message type' actual behavior: no response

import * as express from 'express';
import * as builder from 'botbuilder';
import * as handoff from 'botbuilder-handoff';

const app = express();

// Setup Express Server
app.listen(process.env.port || process.env.PORT || 3978, '::', () => {
    console.log('Server Up');
});

const connector = new builder.ConsoleConnector();
connector.listen();

const NON_MESSAGE_TYPE = 'not message type';

// this is just a simple example, but messages of non 'message' type can exist and have use, such
// as backchannel communication
const bot = new builder.UniversalBot(connector, [
    function (session, args, next) {
        if(session.message.type === NON_MESSAGE_TYPE) {
            session.send('received non standard message type');
        }
    }
]);

const isAgent = (session: builder.Session) => session.message.user.name.startsWith("Agent");

handoff.setup(bot, app, isAgent, {
    mongodbProvider: 'mongodb://localhost:27017/test',
    directlineSecret: 'doesn\t matter',
    retainData: false,
    customerStartHandoffCommand: "HELP"
});

const demoAddress: builder.IAddress = { channelId: 'console',
    user: { id: 'user', name: 'user' }, 
    bot: { id: 'bot', name: 'Bot' },
    conversation: { id: 'userConversation' } 
};

const exampleMessage = new builder.Message()
    .address(demoAddress)
    .toMessage();

exampleMessage.type = NON_MESSAGE_TYPE;

// doesn't get a response
bot.send(exampleMessage);
microsoftly commented 7 years ago

merged #20