Search code examples
pdfbotframeworkskype

How do you send a pdf file using bot framework on a Skype channel?


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.


Solution

  • 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.