我使用 Microsoft Azure 机器人服务和 LUIS 创建了一个聊天机器人。使用经过 LUIS 训练的机器人,我能够接收短信。我已将机器人连接到 Skype channel 。
我不知道如何返回图像附件作为消息的答复。
我听说一些 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 图像中附加“嗨!”当与我的意图“问候”匹配时显示“欢迎”消息。
内容类型=“图像/jpeg”
我不知道如何以及在代码中的何处添加上述内容 URL 以将附件发送到邮件。
有人可以帮我吗?
最佳答案
RAS 是对的,尽管他的代码有错误。您需要在 matches
方法中传递的函数内定义回复消息,否则您将收到 ReferenceError,因为 session 未定义。另外,请使用 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或Thumbnail Cards 。您可以在 Bot Framework Samples github 中查看这些示例的用法。 .
关于azure - 在 Microsoft Azure 聊天机器人中发送图像附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945039/