Bot连接器服务提供404但仍在响应

时间:2018-01-18 09:31:40

标签: node.js azure botframework

我在Azure上运行bot连接器服务,它公开了一个端点,如

  

/ BOT /消息

在Bot通道注册中配置为Messaging端点。此服务接收的每条消息都将发送到后端的服务。

我的代码如下所示:

app.js

var express = require('express');
var routes = require('./routes/index');
var botRoutes = require('./routes/bot');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(favicon(__dirname + '/public/favicon.ico'));
// log format {:method :url :status :response-time ms - :res[content-length]}
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

app.use(responseTime());
app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});
app.use('/', routes);
app.use('/bot', botRoutes);

module.exports = app;

/routes/bot.js

const routerClient = require('../client/routerClient');
var builder = require('botbuilder');
var express = require('express');
var router = express.Router();

var connector = new builder.ChatConnector({
    appId: config.mbf.MICROSOFT_APP_ID,
    appPassword: config.mbf.MICROSOFT_APP_PASSWORD
});

var inMemoryStorage = new builder.MemoryBotStorage();
router.post('/messages', connector.listen());

var bot = new builder.UniversalBot(connector, function (session) {
    var activity = messageToActivity(session.message);
    routerClient.sendToRouter(activity); // sending the received message to router service
}).set('storage', inMemoryStorage); // Register in memory storage

// Send welcome when conversation with bot is started, by initiating the root dialog
bot.on('conversationUpdate', function (message) {
    if (message.membersAdded) {
        logger.debug("Members added", JSON.stringify(message, null, 4));
        message.membersAdded.forEach(function (identity) {
            if (identity.id === message.address.bot.id) {
                bot.beginDialog(message.address, 'welcome');
            }
        });
    }
});
const logUserConversation = (event) => {
    console.log('message: ' + event.text + ', user: ' + event.address.user.name);
    console.log("Event", JSON.stringify(event, null, 4));
};

// Middleware for logging
bot.use({
    receive: function (event, next) {
        console.log("Received");
        logUserConversation(event);
        next();
    },
    send: function (event, next) {
        console.log("Sending");
        logUserConversation(event);
        next();
    }
});

//Dialog to send out replies
bot.dialog('welcome', [
    function (session, args, next) {
        logger.debug("welcome dialog started", args);
        var welcomeCard = new builder.HeroCard(session)
            .title('Welcome')
            .subtitle('How can I help you?')
            .images([
                new builder.CardImage(session)
                    .url('https://<LOGO_IMG_URL>')
                    .alt('<NAME>')
            ])
            .buttons([
                builder.CardAction.imBack(session, "I am unable to login", "Unable to login")
            ]);
        session.send(new builder.Message(session).addAttachment(welcomeCard));
        logger.info("===========welcome msg to MBF===========");
        session.endDialog();
    }
]);

module.exports = router;

我能够在此终点接收消息,并能够将消息中继回其他服务,但在收到并处理每条消息后,我仍然在我的Nodejs服务器日志中看到404。

  

POST / bot / messages 404 23.213 ms - -

有人可以帮我理解导致404的原因吗?

0 个答案:

没有答案