在 Microsoft Azure 聊天机器人中发送图像附件

Send an image attachment in Microsoft Azure Chatbot

我使用 Microsoft Azure 机器人服务和 LUIS 创建了一个聊天机器人。使用在 LUIS 上训练的机器人,我能够接收短信。我已将机器人连接到 Skype 频道。

我不知道如何return 将图像附件作为消息的答复。

我听说某些 Microsoft 机器人框架可以将图像作为附件发送,但我不确定 Azure 机器人服务。

示例代码:

var recognizer = new builder.LuisRecognizer(LuisModelUrl);

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
    .matches('**Greetings**', (session, args) => {session.send('**Hi! Welcome**');});

bot.dialog('/', intents); 

我的案例:

我想附加下面的 URL 图片和 'Hi! Welcome' 消息,当它与我的 Intent 'Greetings' 匹配时。

内容URL:"https://img.clipartfest.com/13e01fd74f423c39c4af7dcc8a7b8455_animated-welcome-sign-animated-welcome-clip-art-images_1300-899.jpeg",

ContentType = "image/jpeg"

我不知道如何以及在何处添加上述内容 URL 在我的代码中以发送邮件附件。

有人可以帮我吗?

使用这样的东西怎么样?

var reply = 
    new builder.Message()
        .setText(session, text)
        .addAttachment({ fallbackText: "Hello!", contentType: 'image/jpeg', contentUrl: picture });
session.send(reply);

使用您的示例,它将是这样的:

var recognizer = new builder.LuisRecognizer(LuisModelUrl);

var reply = 
new builder.Message()
    .setText(session, "Hello!")
    .addAttachment({ fallbackText: text, contentType: 'image/jpeg', contentUrl: "https://img.clipartfest.com/13e01fd74f423c39c4af7dcc8a7b8455_animated-welcome-sign-animated-welcome-clip-art-images_1300-899.jpeg"});  

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('Greetings', (session, args) => {session.send(reply);});

RAS 是对的,尽管他的代码中有错误。您需要在 matches 方法中传递的函数内定义回复消息,否则您将收到 ReferenceError,因为未定义会话。此外,使用 text() 而不是已折旧的 setText()

var recognizer = new builder.LuisRecognizer(LuisModelUrl);

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
    .matches('**Greetings**', (session, args) => {
        var reply = new builder.Message(session)
            .text("Hello!")
            .addAttachment({contentType: "image/jpeg", contentUrl: "https://img.clipartfest.com/13e01fd74f423c39c4af7dcc8a7b8455_animated-welcome-sign-animated-welcome-clip-art-images_1300-899.jpeg"});
    });

bot.dialog('/', intents); 

另一种添加图像的方法是 Hero Cards or Thumbnail Cards. You can see example usages of these in the Bot Framework Samples github

感谢 RAS 和 mgbennet。

它适用于以下代码:

.matches('Greetings', (session, args) => {
            var reply = new builder.Message(); 
            reply.setText(session, "![Greetings](http://aka.ms/Fo983c)");
            session.send(reply);
  })