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

时间:2017-03-20 18:30:00

标签: node.js botframework

我找不到任何方法来处理用户发送给我的Bot的图像。有没有办法获得图像?

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

1 个答案:

答案 0 :(得分:2)

如果用户将某些内容附加到邮件中,则该邮件将位于results.response数组中。您可以使用简单的results.response[0]访问第一个附件。该对象具有contentTypecontentUrl属性,您可以使用这些属性执行任何操作。

为确保您获得图片,您可以提示用户使用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);
    }
})