Bot Framework - 在 NodeJS 中处理用户发送的图像
Bot Framework - Handling user sent images in NodeJS
我找不到任何方法来处理用户发送到我的 Bot 的图像。有什么方法可以获取图片吗?
我发现 是相似的,但对于 C#,我在 node.js 中工作。
如果用户在邮件中附加了一些东西,它将在 results.response
数组中。您可以使用简单的 results.response[0]
访问第一个附件。该对象具有 contentType
和 contentUrl
属性,您可以使用它们来做任何您需要做的事情。
为确保获得图像,您可以使用 builder.Prompts.attachment 提示用户附加内容。当然,他们可以将任何类型的文件附加到他们的邮件中,从文本文件到 .zip,因此您需要检查它是否是合适的文件类型。
bot.dialog('/prompts', [
function (session) {
builder.Prompts.attachment(session, "Send me a file!");
},
function (session, results) {
var firstAttachment = results.response[0],
msg = new builder.Message(session)
.text("You sent a file of type %s and named %s",
firstAttachment.contentType, firstAttachment.name);
msg.addAttachment(attachment);
session.endDialog(msg);
}
})
我找不到任何方法来处理用户发送到我的 Bot 的图像。有什么方法可以获取图片吗?
我发现
如果用户在邮件中附加了一些东西,它将在 results.response
数组中。您可以使用简单的 results.response[0]
访问第一个附件。该对象具有 contentType
和 contentUrl
属性,您可以使用它们来做任何您需要做的事情。
为确保获得图像,您可以使用 builder.Prompts.attachment 提示用户附加内容。当然,他们可以将任何类型的文件附加到他们的邮件中,从文本文件到 .zip,因此您需要检查它是否是合适的文件类型。
bot.dialog('/prompts', [
function (session) {
builder.Prompts.attachment(session, "Send me a file!");
},
function (session, results) {
var firstAttachment = results.response[0],
msg = new builder.Message(session)
.text("You sent a file of type %s and named %s",
firstAttachment.contentType, firstAttachment.name);
msg.addAttachment(attachment);
session.endDialog(msg);
}
})