Search code examples
c#botframeworkskype-bots

File attachment works in Microsoft Bot Emulator but not in Skype


I want to send an attachment (.txt) to Skype client using Microsoft Bot Framework V3 with Bot Builder Nuget package (3.2.0)

This is how I created the attachment:

var replayFile = new Microsoft.Bot.Connector.Attachment();
replayFile.Name = "FileName";
replayFile.Content = "ByteArray";
replayFile.ContentType = "text/plain";

This works for the Bot Emulator (3.0.0.59), but my skype client(7.26.0.101) on Windows 10 sees only the message's text, but not the attachment.

I also tried Skype's Web UI in outlook.com, also no attachment.

In this document: https://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html

It says:

If it is a file then it will simply come through as a link

Does this mean the only way to send a file using the BotFramework is via a link? Sending directly is not possible? But how come it works using the Emulator?


Solution

  • I have no idea why does it work in the Emulator, but sending a byte array through the Content property is not supported. However, according to this and this comments, you can send an attachment using a base64 encoded data URI:

    byte[] data = GetAttachmentData();
    var contentType = "text/plain";
    var replayFile = new Microsoft.Bot.Connector.Attachment
    {
        Name = "FileName.txt",
        ContentUrl = $"data:{contentType};base64,{Convert.ToBase64String(data)}",
        ContentType = contentType
    };