我找不到任何方法来处理用户发送到我的机器人的图像。有什么办法可以获取图像吗?
我找到了this这是类似的,但对于 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);
}
})
关于node.js - Bot Framework - 在 NodeJS 中处理用户发送的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42911325/