我的问题本质上与 this github issue 相同,然后是 BotBuilder 框架的 Node 版本。
当机器人被添加到具有多个用户的 channel 时,它会对每条消息使用react,但这不是它的目的。我打算通过拦截消息来解决此问题,如果其中包含机器人的提及,则将允许其正常流动,否则取消操作。但是我找不到合适的函数来覆盖。有什么建议吗?
最佳答案
您可以使用node 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
。在此示例中,机器人仅打印有关每条消息的一些信息,但您可以修改行为以过滤消息并检查提及情况。
关于node.js - 如何阻止消息在机器人构建器框架中被识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111126/