I would like to send a pdf file using bot-framework on a Skype channel. Similar to how this is done on a telegram channel. Bot Framework: send pdf file on Telegram. I am really struggling to find useful documentation on using the Skype channel with bot-framework. CardAttachments don’t work even though they were coming soon two years ago. Like the Telegram example, I have the pdf as a base64 string. I can’t use a link as the pdf is generated from the user’s inputs.
This is how I send images. I assume it is something similar.
var cardAttachment = new Attachment()
{
ContentUrl = "https://my.url/file.png",
ContentType = "image/png",
Name = "filename.png",
};
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>() { cardAttachment };
reply.Text = "Some useful text to go along with the image.";
await turnContext.SendActivityAsync(reply, cancellationToken);
I tried
var values = new Dictionary<string, string>();
...
var content = new FormUrlEncodedContent(values);
var response = await Client.PostAsync(@"https://my.url/report.php", content);
var report = await response.Content.ReadAsByteArrayAsync();
var cardAttachment = new Attachment()
{
ContentUrl = "data:application/pdf;base64," + Convert.ToBase64String(report),
ContentType = "application/pdf",
Name = $"{answers.Name}.pdf",
};
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>() { cardAttachment };
reply.Text = $"{answers.Name} here is your report.";
await turnContext.SendActivityAsync(reply, cancellationToken);
It seems to be close but quite right.
Update: While Skype blocks you from sending PDFs as attachments in any form (links, local file or Base64Strings) you can send them as links by simply embedding the link in your text. It looks like you can send links and local files to WebChat. Sending Bot Reply message with attachment using Bot Framework has lots of examples of various approaches.
2
Answers
While Skype blocks you from sending PDFs as attachments in any form (links, local file or Base64Strings) you can send them as links by simply embedding the link in your text.
I know as of this time last year, the Skype channel did not support sending PDF attachments to users due to security concerns – you can see more details regarding this problem here. I haven’t been able to find any recent documentation contrary to that, nor was I able to send a PDF attachment through my test bot to Skype. I could, hower, send a PDF to the Emulator and WebChat. Unfortunately, I believe sending PDF attachments is still unsupported by the Skype channel.
Here is the sample code I used to send a PDF attachment to the emulator and WebChat:
Sorry I could not have been of more help.