1

I want my bot to send a PDF file to the user. I have the PDF as a base64 string and tried to send it through an attachment:

Attachment attachment1 = new Attachment();
attachment1.Name = "name.pdf";
attachment1.ContentType = "application/pdf";
attachment1.ContentUrl = "data:application/pdf;base64," + base64String;

var m = context.MakeMessage();
m.Attachments.Add(attachment1);
m.Text = "File";

await context.PostAsync(m);

Within the emulator, it just doesn't work but in the channels Telegram and Facebook (which I need), the bot just outputs an error...

Has someone already succeed in it?

Note: Using an HTTP address works fine, but I need to use the base64 string

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Ynnad
  • 303
  • 4
  • 18
  • Actually the way I did it was working, the only problem being my base64 string was too big (so file too huge) ! Which seems strange since Telegram is supposed to deal with files until 50MB... – Ynnad May 09 '17 at 15:29

2 Answers2

1

As this method in botframework call sendDocument method of Telegram, and this method in its document property get http url or a file_id, so you can't pass base64String to this method as a valid document type.

You can follow the valid type of the document passing into the telegram in this link (also, see the following image).

enter image description here

OmG
  • 18,337
  • 10
  • 57
  • 90
0

The pdf file must be embedded resource. Hope it help.

if (this.channelid == "telegram")
{
    var url = string.Format("https://api.telegram.org/bot{0}/sendDocument", Settings.tokentelegram);

    Assembly _assembly;
    Stream file;

    using (var form = new MultipartFormDataContent())
    {
        form.Add(new StringContent(this.chat_id, Encoding.UTF8), "chat_id");

        _assembly = Assembly.GetExecutingAssembly();
        file = _assembly.GetManifestResourceStream("Namespace.FolderResourses.name.pdf");

        form.Add(new StreamContent(file), "document", "name.pdf");

        using (var client = new HttpClient())
        {
            await client.PostAsync(url, form);
        }
    }
}  
Irbis377
  • 1
  • 3