我想创建Luis意图,它将识别消息是附件并调用相应的对话框。 我正在使用节点js
我正在获得附件但想要进入对话
var bot = new builder.UniversalBot(connector, function (session) {
var msg = session.message;
if (msg.attachments.length) {
// Message with attachment, proceed to download it.
// Skype & MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
var attachment = msg.attachments[0];
var fileDownload = checkRequiresToken(msg)
? requestWithToken(attachment.contentUrl)
: request(attachment.contentUrl);
fileDownload.then(
function (response) {
// Send reply with attachment type & size
var reply = new builder.Message(session)
.text('Attachment of %s type and size of %s bytes received.', attachment.contentType, response.length);
session.send(reply);
}).catch(function (err) {
console.log('Error downloading attachment:', { statusCode: err.statusCode, message: err.response.statusMessage });
});
} else {
// No attachments were sent
var reply = new builder.Message(session)
.text('Hi there! This sample is intented to show how can I receive attachments but no attachment was sent to me. Please try again sending a new message with an attachment.');
session.send(reply);
}
});
答案 0 :(得分:1)
现在使用IntentRecognizer.onEnabled()
修复此问题。 (example here)
对于这个应用程序,你要做的是检查
session.message.attachments
。如果它存在,那么您不希望将任何session.message.text
发送到LUIS进行识别。
var recognizer = new builder.LuisRecognizer('LUIS-ENDPOINT')
.onEnabled(function (session, callback) {
// Check to see if this recognizer should be enabled
if (session.message.attachments) {
// Do not send to LUIS
callback(null, false);
} else {
callback(null, true);
}
});