如何停止在bot生成器框架中识别的消息

我的问题基本上与这个github问题相同,但是对于BotBuilder框架的Node版本。

当机器人被添加到多个用户的频道时,它会对每一条消息做出反应,这不是它的目的。 我打算通过拦截这个消息来解决这个问题,如果它包含了一个bot的提到,它将被允许正常stream动,否则取消这个动作。 但是我无法find正确的function重写。 有什么build议么?

您可以使用节点SDK轻松拦截消息。 我给你一个示例代码:

server.post('/api/messages', connector.listen()); var bot = new builder.UniversalBot(connector); bot.use({ botbuilder: function (session, next) { myMiddleware.doSthWithIncomingMessage(session, next); }, send: function (event, next) { myMiddleware.doSthWithOutgoingMessage(event, next); } }) module.exports = { doSthWithIncomingMessage: function (session, next) { console.log(session.message.text); next(); }, doSthWithOutgoingMessage: function (event, next) { console.log(event.text); next(); } } 

现在,每个入站消息(从用户到机器人)都将触发doSthWithIncomingMessage ,并且每个出站消息(从机器人到用户)都将触发doSthWithOutgoingMessage 。 在这个例子中,机器人只是打印一些关于每条消息的信息,但是你可以修改行为来过滤消息并检查提及。