簡體   English   中英

如何解決Skype bot中的圖像附件顯示問題?

[英]How to resolve image attachment display issue in skype bot?

我在Skype中為我的機器人使用了bot框架(C#SDK)。 它在模擬器中工作正常,但是當我在Skype上運行它時,它不顯示圖像附件。 我已經檢查了文檔,但找不到任何解決方案。 我不確定這是我還是Skype的問題。 注意:我在手機上使用的是Windows 10的Skype和android的Skype(在這兩種方式中均無法使用)

這是模擬器中附件的http響應

仿真器映像

這是Skype中的圖像

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(位於用戶網絡內的服務器上)訪問圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM