休息 API 附件错误
Rest API attachment error
我在使用机器人框架 REST 通过 Skype 频道发送附件时遇到问题 API。
我可以使用这样的 json 消息正确发送图像:
{
"type":"message",
"timestamp":"2017-05-22T11:31:36.2281894Z",
"from":{
"name":"MyBot"
},
"recipient":{
"id":"29:1-Dl1xMx6G2qGya5O5BgTZJhc0fUKOiQLctt74CmwJ3PVJNgkocpf3LY626py9UIO"
},
"text":"It works!",
"attachments": [
{
"contentType": "image/jpg",
"contentUrl": "https://g87a2173.ngrok.io/content/attachments/65f2be10-e61e-424e-9ea1-e05f1002fd19",
"name": "image.jpg"
}
]
}
但是如果我发送的文件的内容类型不是图像,我就会出错。
例如,如果我发送
{
"type":"message",
"timestamp":"2017-05-22T11:31:36.2281894Z",
"from":{
"name":"MyBot"
},
"recipient":{
"id":"29:1-Dl1xMx6G2qGya5O5BgTZJhc0fUKOiQLctt74CmwJ3PVJNgkocpf3LY626py9UIO"
},
"text":"Not working!",
"attachments": [
{
"contentType": "audio/wav",
"contentUrl": "https://g87a2173.ngrok.io/content/attachments/e58bcefa-7060-464f-96ee-78d2795ec80f",
"name": "audio.wav"
}
]
}
我收到 400 错误
{
"error": {
"code": "BadArgument",
"message": "Unknown attachment type"
}
}
API reference documentation 表示
An attachment may be a media file (e.g., audio, video, image, file) or
a rich card
所以我哪里错了?
谢谢
我对 C# 代码进行了相同的尝试并得到了相同的结论:在 Skype 频道上,我们得到了一个 Unknown attachment type
异常。
在模拟器和 Slack 上工作(获得 link 下载 wav 文件)
一定是频道限制是的,或者是bug。
无论如何你可以尝试使用 AudioCard
:我测试了它(在 C# 代码中)并且它在 Skype 上工作:
示例代码在这里:https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/cards-RichCards
我发现的最佳通用解决方案是发送一个带有指向文件 URI 的 AdaptiveOpenUrlAction 的自适应卡,如下所示:
var card = new AdaptiveCard("1.0");
card.Actions.Add(new AdaptiveOpenUrlAction{
Title = "myDocument.docx",
Url = "https://example.com/documents/myDocument.docx"
});
var attachment = new Attachment(AdaptiveCard.ContentType, content:card);
我在使用机器人框架 REST 通过 Skype 频道发送附件时遇到问题 API。
我可以使用这样的 json 消息正确发送图像:
{
"type":"message",
"timestamp":"2017-05-22T11:31:36.2281894Z",
"from":{
"name":"MyBot"
},
"recipient":{
"id":"29:1-Dl1xMx6G2qGya5O5BgTZJhc0fUKOiQLctt74CmwJ3PVJNgkocpf3LY626py9UIO"
},
"text":"It works!",
"attachments": [
{
"contentType": "image/jpg",
"contentUrl": "https://g87a2173.ngrok.io/content/attachments/65f2be10-e61e-424e-9ea1-e05f1002fd19",
"name": "image.jpg"
}
]
}
但是如果我发送的文件的内容类型不是图像,我就会出错。
例如,如果我发送
{
"type":"message",
"timestamp":"2017-05-22T11:31:36.2281894Z",
"from":{
"name":"MyBot"
},
"recipient":{
"id":"29:1-Dl1xMx6G2qGya5O5BgTZJhc0fUKOiQLctt74CmwJ3PVJNgkocpf3LY626py9UIO"
},
"text":"Not working!",
"attachments": [
{
"contentType": "audio/wav",
"contentUrl": "https://g87a2173.ngrok.io/content/attachments/e58bcefa-7060-464f-96ee-78d2795ec80f",
"name": "audio.wav"
}
]
}
我收到 400 错误
{
"error": {
"code": "BadArgument",
"message": "Unknown attachment type"
}
}
API reference documentation 表示
An attachment may be a media file (e.g., audio, video, image, file) or a rich card
所以我哪里错了?
谢谢
我对 C# 代码进行了相同的尝试并得到了相同的结论:在 Skype 频道上,我们得到了一个 Unknown attachment type
异常。
在模拟器和 Slack 上工作(获得 link 下载 wav 文件)
一定是频道限制是的,或者是bug。
无论如何你可以尝试使用 AudioCard
:我测试了它(在 C# 代码中)并且它在 Skype 上工作:
示例代码在这里:https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/cards-RichCards
我发现的最佳通用解决方案是发送一个带有指向文件 URI 的 AdaptiveOpenUrlAction 的自适应卡,如下所示:
var card = new AdaptiveCard("1.0");
card.Actions.Add(new AdaptiveOpenUrlAction{
Title = "myDocument.docx",
Url = "https://example.com/documents/myDocument.docx"
});
var attachment = new Attachment(AdaptiveCard.ContentType, content:card);