Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解决skype bot中的图像附件显示问题?_C#_Botframework_Skype - Fatal编程技术网

C# 如何解决skype bot中的图像附件显示问题?

C# 如何解决skype bot中的图像附件显示问题?,c#,botframework,skype,C#,Botframework,Skype,我正在skype中为我的机器人程序使用机器人程序框架(C#SDK)。它在模拟器中工作正常,但当我在skype上运行它时,它不会显示图像附件。 我检查了文档,但找不到任何解决方案。我不确定这是我这边的问题还是skype的问题。 注意:我在手机上使用的是适用于windows 10的skype和适用于android的skype(在这两种情况下都不起作用) 下面是emulator中附件的http响应 这是skype中的图像 下面是生成attachement的方法 public Attachment

我正在skype中为我的机器人程序使用机器人程序框架(C#SDK)。它在模拟器中工作正常,但当我在skype上运行它时,它不会显示图像附件。 我检查了文档,但找不到任何解决方案。我不确定这是我这边的问题还是skype的问题。 注意:我在手机上使用的是适用于windows 10的skype和适用于android的skype(在这两种情况下都不起作用)

下面是emulator中附件的http响应

这是skype中的图像

下面是生成attachement的方法

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;
    }      
}
下面是调用此方法的代码。我从我们的服务器“HumanCollaborator”获取此映像,并使用套接字与之通信。 对于插座,我使用“websocket sharp”库

专用异步任务StandardInfoFormComplete(IDialogContext上下文,IAwaitable结果)
{
尝试
{
var form=等待结果;
EventOccursed=false;
SocketStream.ws.OnMessage+=(发送方,e)=>
{
尝试
{
var json=e.数据;
StandardInfoJson响应=JsonConvert.DeserializeObject(json);
var数据=响应数据;
如果(数据[0].result.ToLower()=“确定”)
{
//对于图表报告
var chartAttachment=card.ChartCard(数据);
replyToConversation.Attachments.Add(图表附件);
PostAsync(replyToConversation);
}
如果(数据[0]。结果。ToLower()=“错误”)
{
var replyToConversation=context.MakeMessage();
var消息=数据[0]?.消息;
replyToConversation.Text=消息;
PostAsync(replyToConversation);
}
}
捕获(NullReferenceException ex)
{
Debug.WriteLine(例如StackTrace);
}
EventOccursed=true;
};
//构建json字符串的botRequest部分
Utilities.StringBuilder.JsonStringBuilder(上下文、结果);
//实例化JSONDataObjects类
JSONDataObjects jdo=新的JSONDataObjects();
//创建JSON字符串
字符串输出=JsonConvert.SerializeObject(jdo,Formatting.Indented);
Debug.WriteLine(“用户:\n”+输出);
//将Json对象发送给人工协作者
ws.Send(输出);
wait context.PostAsync(“生成响应…请耐心等待…”);
睡眠(8000);
如果(!eventoccurrent)
等待上下文。PostAsync(“服务器正忙…请稍后再试”);
上下文。完成(true);
}
捕获(例外e)
{
字符串回复;
if(e.InnerException==null)
{
reply=$“您退出了--也许下次可以完成!”;
}
其他的
{
reply=“对不起,我短路了。请再试一次。”;
}
等待上下文。PostAsync(回复);
}
}

请帮帮我,我做错了什么。谢谢

我没有所有代码来重播您的案例,但我看到了一件重要的事情:

else
{
    Attachment attachment = new Attachment();
    attachment.Content = "No Chart Report Found";
    return attachment;
}
在这里,您不应该创建附件,因为您没有要附加的内容。这将引发错误,因为缺少
ContentType

您可以修改调用您的
图表卡的代码吗
:当其参数(您的
StandardInfoData[]
)为空时,它不应该调用它

我无法使用您提供的代码进行更多测试,但您还应该检查从Skype呼叫时套接字呼叫中的数据是否正常(如通过输出值或任何其他方式),这将有助于您的调查


编辑:在对这个答案进行了大量评论之后,问题似乎来自Skype无法访问图像(位于用户网络内的服务器上)

请分享您如何生成图像附件的代码,以便我们能够复制, thanks@NicolasR我已经用代码更新了这个问题。事实上,它在emulator中运行良好,但在skype中不起作用。如果是附加问题,它也不应该在emulator中工作。您是否尝试过该解决方案?Skype也不是因为模拟器是允许的。我像你一样测试了发送内容,得到了“ContentType丢失”。错误是的,我尝试了你告诉我的解决方案。我认为问题在于图像url。因为当我尝试其他url链接时,它会工作,但当我尝试显示缓存在服务器上的报表图像url时,它不会工作。你认为它是skype http://:8080/human collaborator/sessionUser/0d36b8eb-1d15-43f8-9b40-bce23b43f501/chartReport的有效url吗?reportId=4e2ec095-170e-4042-b030-27713b5d6c8d&format=img&type=pieMaybe,也许不是。例如,不知道您的服务器限制。但这可能是一个重要的问题,因为该链接在浏览器中运行良好,显示的图像分辨率为1024x768。
else
{
    Attachment attachment = new Attachment();
    attachment.Content = "No Chart Report Found";
    return attachment;
}