路易斯意图识别附件
Luis intent to identify attachment
我想创建 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);
}
});
这是目前使用 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);
}
});
我想创建 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);
}
});
这是目前使用 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);
}
});