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

How to resolve image attachment display issue in skype bot?

我在 Skype 中为我的机器人使用机器人框架 (C# SDK)。它在模拟器中运行良好,但是当我在 Skype 上 运行 它时,它不显示图像附件。 我检查了文档,但找不到任何解决方案。我不确定这是我这边的问题还是 Skype 的问题。 注意:我在 windows 10 上使用 skype,在我的手机 phone 上使用 skype 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);
        }
    }

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

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

else
{
    Attachment attachment = new Attachment();
    attachment.Content = "No Chart Report Found";
    return attachment;
}

在这里你不应该创建附件,因为你没有任何东西可以附加。这将引发错误,因为缺少 ContentType

您能否修改调用您的 ChartCard 的代码:当其参数(您的 StandardInfoData[])为空时不应调用它。

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

编辑: 在对这个答案发表大量评论后,问题似乎出在无法从 Skype(位于用户网络内的服务器上)访问图像这一事实)