我在我的机器人skype中使用bot框架(C#SDK)。它在模拟器中工作正常,但是当我在Skype上运行它时,它不会显示图像attachemnts。 我检查了文档,但我找不到任何解决方案。我不确定这是我的问题还是在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);
}
}
请帮助我,我做错了什么。感谢
答案 0 :(得分:2)
我没有重播你的案例的所有代码,但我看到一件重要的事情:
else
{
Attachment attachment = new Attachment();
attachment.Content = "No Chart Report Found";
return attachment;
}
在此您不应创建附件,因为您无需附加任何内容。这将导致错误,因为ContentType
缺失。
您是否可以修改调用ChartCard
的代码:当其参数(您的StandardInfoData[]
)为空时,不应调用该代码。
我无法使用您提供的代码进行更多测试,但您还应检查从Skype呼叫时Socket呼叫中的数据是否正常(例如通过输出值或任何其他方式),这将有助于你的调查
编辑:在对此答案进行了大量评论之后,看起来问题来自于无法从Skype(位于用户网络内的服务器上)访问该图像的事实