botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Uploading images as part of attachment

Open MironV opened this issue 10 years ago • 4 comments

Sending images to people that are already uploaded somewhere works perfectly! In one of the scenarios in my bot, I have it create a GIF on-the-fly and then upload it directly (because I don't want to upload it to a hosting service first since it's a one-off). I know how to get this working with Facebook (see curl signature below) but how can I do this in BotBuilder?

curl
-F recipient='{"id":"USER_ID"}'
-F message='{"attachment":{"type":"image", "payload":{}}}'
-F filedata=@/tmp/shirt.png
"https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

MironV avatar Jul 29 '16 19:07 MironV

You can send the image in-line:

        // send image inline
        WebClient webClient = new WebClient();
        byte[] data = {your image as a byte array}
        var image64 = "data:image/jpeg;base64," + Convert.ToBase64String(data);
        reply.Attachments.Add(new Attachment()
        {
            ContentUrl = image64,
            ContentType = "image/jpeg",
        });

LarsLiden avatar Jul 29 '16 19:07 LarsLiden

That's awesome, I'll give it a try! Thanks!

MironV avatar Jul 29 '16 19:07 MironV

any thoughts on how this can be done with Node.js?

srichakradhar avatar Nov 30 '17 02:11 srichakradhar

I tried:

var fileRead = fs.readFileSync("/home/srichakradhar/Documents/bots/PurchaseHelper/docs/IT Purchase Request Workbook.xlsx");
    var base64File = fileRead.toString('base64,');
    var attachment = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + base64File

But Skype shows warning and doesn't send any message (reply) image

srichakradhar avatar Nov 30 '17 02:11 srichakradhar