node.js - Bot Framework - 在 NodeJS 中处理用户发送的图像

标签 node.js botframework

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

我找到了this这是类似的,但对于 C#,我正在使用 Node.js。

最佳答案

如果用户将某些内容附加到消息中,它将位于 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);
    }
})

关于node.js - Bot Framework - 在 NodeJS 中处理用户发送的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42911325/

相关文章:

javascript - Node JS 浏览器模拟(cookies、session、headers)

windows - 在 Windows 7 上通过 cygwin/node.js 创建音频 Sprite 需要一些帮助

debugging - 如何调试导致 100% cpu 使用的 node.js?

python - MS Teams 中的主动消息传递

c# - Microsoft Bot Framework - 如何知道用户时间和 IP 以跟踪位置

javascript - NodeJS 可执行文件无法通过 `process.argv` 接收命令参数

node.js - 连续帧不能跟随当前操作码

botframework - 如何在 bot framework v4 中形成英雄卡片轮播

c# - 机器人框架: 'State size exceeded configured limit.'

botframework - 未触发自适应卡片操作