【问题标题】:How to resolve image attachment display issue in skype bot?如何解决 Skype 机器人中的图像附件显示问题?
【发布时间】: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


【解决方案1】:

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

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

在这里您不应该创建附件,因为您没有要附加的内容。这将引发错误,因为缺少 ContentType

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

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

编辑:在很多 cmets 回答这个问题之后,看起来问题来自 Skype 无法访问图像(位于用户网络内的服务器上)

【讨论】:

  • 它没有帮助 实际上,它在模拟器中运行良好,但在 Skype 中却不行。如果是附件问题,它也不应该在模拟器中工作
  • 您尝试过解决方案吗?这并不是因为模拟器允许 Skype 也允许。我像您一样测试了发送内容并得到“缺少 ContentType”。错误
  • 是的,我尝试了您告诉我的解决方案。我认为问题在于图片网址。因为当我尝试其他一些 url 链接时它可以工作,但是当我尝试显示缓存在服务器上的报告图像 url 时不起作用。您认为这是 Skype 的有效 url http://:8080/human-collaborator/sessionUser/0d36b8eb-1d15-43f8-9b40-bce23b43f501/chartReport?reportId=4e2ec095-170e-4042 -b030-27713b5d6c8d&format=img&type=pie
  • 也许,也许不是。例如,不知道您的服务器限制。但这可能是一个重要的问题是的
  • 此链接在浏览器中运行良好,并显示分辨率为 1024x768 的图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-27
  • 2017-05-10
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
相关资源
最近更新 更多