skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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:

    var reply = turnContext.Activity.CreateReply();
    
    // Create an attachment.
    var attachment = new Attachment
    {
        ContentUrl = "<path_to_file>/<filename>.pdf",
        ContentType = "application/pdf",
        Name = "<filename>.pdf",
    };
    
    // Add the attachment to our reply.
    reply.Attachments = new List<Attachment>() { attachment };
    
    // Send the activity to the user.
    await turnContext.SendActivityAsync(reply, cancellationToken);
    

    Sorry I could not have been of more help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search