我正在尝试将从一个用户发送到bot的附件路由到另一个用户。电脑正在尝试从模拟器发送到模拟器/电报/ Skype,但是当我尝试从skype / telegram发送它时,它工作得很好(skype什么也没说,电报辩称:&& #34; POST到 mybot 失败:POST到机器人的端点失败,HTTP状态为500")。我应该在哪里找到问题?
这是我的代码:
if (mes.Attachments != null && mes.Attachments.Any())
{
var list = new List<Attachment>();
foreach (var attachment in mes.Attachments)
{
using (HttpClient httpClient = new HttpClient())
{
// Skype attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
if (mes.ChannelId.Equals("skype", StringComparison.InvariantCultureIgnoreCase) &&
new Uri(attachment.ContentUrl).Host.EndsWith("skype.com"))
{
var mstoken = await new MicrosoftAppCredentials().GetTokenAsync();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
mstoken);
}
var responseMessage = await httpClient.GetAsync(attachment.ContentUrl);
var ms = await ConvertContentToByteArray(responseMessage);
var sendAttachment = new Attachment()
{
ContentType = attachment.ContentType,
Name = attachment.Name,
ContentUrl = String.Format("data:image/png;base64,{1}", attachment.ContentType,
Convert.ToBase64String(ms))
};
list.Add(sendAttachment);
}
}
message.Attachments = list;
message.AttachmentLayout = mes.AttachmentLayout;
}
await connector.Conversations.SendToConversationAsync((Activity)message);
&#34; MES&#34;是收到的消息,&#34;消息 - 输出。
提前感谢您的回答!
更新1 :我设法解决了发送/接收文件的问题(请参阅下面的回答)。遗憾的是,出现了文件大小限制的新问题(请参阅Useful post)。
一些对我有用的链接:Send Attachment Sample,Receive Attachment Sample,Useful post,Some other receiving example
答案 0 :(得分:1)
上面的代码是正确的,并且工作正常(如果附件的大小不是太大)。我的问题(和愚蠢的错误)是在没有空检查的情况下在其他地方使用mes.Text。 Skype / Telegram中的附件有mes.Text == null。