【发布时间】:2017-07-10 10:38:32
【问题描述】:
我在 Skype 中为我的机器人使用机器人框架 (C# SDK)。它在模拟器中运行良好,但是当我在 Skype 上运行它时,它不显示图像附件。 我检查了文档,但找不到任何解决方案。我不确定这是我的问题还是Skype的问题。 注意:我在我的手机上使用 Skype for Windows 10 和 Skype for android(这两种都不起作用)
这是模拟器中附件的http响应
这是Skype中的图片
这里是生成附件的方法
public Attachment ChartCard(StandardInfoData[] data)
{
if (data != null && data.Length != 0)
{
string chartUrl = data[0]?.report?.url;
Attachment attachment = new Attachment();
attachment.ContentUrl = chartUrl;
attachment.ContentType = "image/png";
attachment.Name = "Chart Report";
return attachment;
}
else
{
Attachment attachment = new Attachment();
attachment.Content = "No Chart Report Found";
return attachment;
}
}
这是调用此方法的代码。我从我们的服务器“Human Collaborator”获取此图像并使用套接字与其通信。 对于套接字,我使用“websocket-sharp”库
private async Task StandardInfoFormComplete(IDialogContext context, IAwaitable<StandardInfoForm> result)
{
try
{
var form = await result;
eventOccured = false;
SocketStream.ws.OnMessage += (sender, e) =>
{
try
{
var json = e.Data;
StandardInfoJson response = JsonConvert.DeserializeObject<StandardInfoJson>(json);
var data = response.data;
if (data[0].result.ToLower() == "ok")
{
// For chart reports
var chartAttachment = card.ChartCard(data);
replyToConversation.Attachments.Add(chartAttachment);
context.PostAsync(replyToConversation);
}
if (data[0].result.ToLower() == "error")
{
var replyToConversation = context.MakeMessage();
var message = data[0]?.message;
replyToConversation.Text = message;
context.PostAsync(replyToConversation);
}
}
catch (NullReferenceException ex)
{
Debug.WriteLine(ex.StackTrace);
}
eventOccured = true;
};
//builds the botRequest part of json string
Utilities.StringBuilder.JsonStringBuilder(context, result);
// Instantiate JSONDataObjects class
JSONDataObjects jdo = new JSONDataObjects();
//Create JSON string
string output = JsonConvert.SerializeObject(jdo, Formatting.Indented);
Debug.WriteLine("USER: \n" + output);
//Sending the Json object to Human-Collaborator
SocketStream.ws.Send(output);
await context.PostAsync("Generating response.....Please Be Patient.....");
Thread.Sleep(8000);
if (!eventOccured)
await context.PostAsync("Server is busy ... Please try again later");
context.Done(true);
}
catch (Exception e)
{
string reply;
if (e.InnerException == null)
{
reply = $"You quit --maybe you can finish next time!";
}
else
{
reply = "Sorry, I've had a short circuit. Please try again.";
}
await context.PostAsync(reply);
}
}
请帮助我做错了什么。谢谢
【问题讨论】:
-
请分享您如何生成图像附件的代码,以便我们能够复制,谢谢
-
@NicolasR 我已经用代码更新了问题
标签: c# botframework skype