Bot框架 – 在NodeJS中处理用户发送的图像

我找不到任何方式来处理用户发送到我的机器人的图像。 有什么办法可以获得图像?

我发现这是类似的,但对于C#,我在node.js工作。

如果用户将一些东西附加到消息中,它将在results.response数组中。 您可以通过一个简单的results.response[0]来访问第一个附件。 这个对象有contentTypecontentUrl属性,你可以用它来做任何你需要做的事情。

为了确保你得到一个图像,你可以提示用户使用builder.Prompts.attachment附加一些东西。 当然,他们可以将任何types的文件附加到他们的消息,从文本文件到.zip,所以你需要检查它是一个合适的文件types。

 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); } })