Bot框架:同时拥有QnA Maker和IntentDialogs

时间:2017-09-03 01:02:45

标签: node.js botframework

是否可以同时使用QnAMakerDialog和自定义IntentDialog?因此,QnA Maker将回答知识库中所有与FAQ相关的查询,我还可以将一些自定义命令硬编码到BotFramework中。

类似的东西:

var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
    recognizers: [recognizer],
    defaultMessage: 'Sorry, I did not understand that.',
    qnaThreshold: 0.3
});

bot.dialog('/', basicQnAMakerDialog);

bot.dialog( new builder.IntentDialog()
.matchesAny([/Test/i], [
        function (session) {
           session.send('This is not from QnA Maker');
        }
])
);

我输入'Test'时的当前输出是来自QnA制造商的defaultMessage

1 个答案:

答案 0 :(得分:1)

我明白了。这段代码给了我想要的输出:

var qnarecognizer = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: '', 
    subscriptionKey: '',
    top:4});

var intentrecognizer = new builder.IntentDialog();

var intents = new builder.IntentDialog({ recognizers: [intentrecognizer, qnarecognizer] });
bot.dialog('/', intents);

intents.matches('qna', [
    function (session, args, next) {
        var answerEntity = builder.EntityRecognizer.findEntity(args.entities, 'answer');
        session.send(answerEntity.entity);
    }
]);

intents.matchesAny([/Test/i], [
        function (session) {
           session.send('This is not from QnA Maker.');
        }
]);

intents.onDefault( [
        function (session) {
           session.send('Sorry, I don\'t know that.');
        }
]);