我的问题是在Microsoft Teams的群聊中处理与机器人的对话。我正在尝试MS教程中的基本示例:
var builder = require('botbuilder');
var restify = require('restify');
//=========================================================
// Bot Setup
//=========================================================
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
//=========================================================
// Bots Dialogs
//=========================================================
var intents = new builder.IntentDialog();
bot.dialog('/', intents);
intents.matches(/^change name/i, [
function (session) {
session.beginDialog('/profile');
},
function (session, results) {
session.send('Ok... Changed your name to %s', session.userData.name);
}
]);
intents.onDefault([
function (session, args, next) {
if (!session.userData.name) {
session.beginDialog('/profile');
} else {
next();
}
},
function (session, results) {
session.send('Hello %s!', session.userData.name);
}
]);
bot.dialog('/profile', [
function (session) {
builder.Prompts.text(session, 'Hi! What is your name?');
},
function (session, results) {
session.userData.name = results.response;
session.endDialog();
}
]);
这个简单的对话框在一对一聊天中很有用:https://screencast.com/t/VgjlxYMea
但在群聊中,识别意图存在问题:https://screencast.com/t/f7JAr7HFAY7
我的第一个想法是,提到机器人我应该更新意图的模式,从/^change name/i
到/.*change name/i
,显然机器人开始认识到意图:https://screencast.com/t/i66rDQj0pC ...但是进入对话框仍然没有运气。