Reputation: 209
I am using bot framework (C# SDK) for my bot in skype. It works fine in the emulator but when i run it on the skype, it does not display image attachemnts. I have checked documentation but i couldn't find any solution. I am not sure if it is the problem on my end or in the skype. Note: I am using skype for windows 10 and skype for android on my cell phone (does not work in either of these)
Here is http response for attachement in emulator
Here is the image in skype
Here is the method that generates 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;
}
}
Here is the code that calls this method. I am getting this image from our server "Human Collaborator" and using sockets to communicate with it. For sockets i am using "websocket-sharp" library
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);
}
}
Please help me what i am doing wrong. Thanks
Upvotes: 1
Views: 312
Reputation: 14599
I don't have all the code to replay your case but I see one important thing:
else
{
Attachment attachment = new Attachment();
attachment.Content = "No Chart Report Found";
return attachment;
}
Here you should not create an attachment as you have nothing to attach. This will throw an error because the ContentType
is missing.
Can you modify the code that is calling your ChartCard
: it should not call it when its parameter (your StandardInfoData[]
) is empty.
I am not able to test more with the code you provided, but you should also check if your data in the Socket call is okay when calling from Skype (like by outputting the value or any other way), it will help in your investigation
EDIT: after a lot of comments on this answer, looks like the problem comes from the fact that the image is not reachable from Skype (located on a server inside user's network)
Upvotes: 2