Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an image rather than a link

I'm using the Microsoft Bot Framework with Cognitive Services to generate images from a source image that the user uploads via the bot. I'm using C#.

The Cognitive Services API returns a byte[] or a Stream representing the treated image.

How can I send that image directly to my user? All the docs and samples seem to point to me having to host the image as a publically addressable URL and send a link. I can do this but I'd rather not.

Does anyone know how to simple return the image, kind of like the Caption Bot does?

like image 651
Martin Kearn Avatar asked Aug 31 '16 09:08

Martin Kearn


People also ask

Why are my picture messages being sent as a link?

Because they haven't configured MMS properly, and has data turned off. There's a setting in the messaging app you can turn on to automatically retrieve MMS.

Can you use an image as a link?

To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.


1 Answers

You should be able to use something like this:

var message = activity.CreateReply("");
message.Type = "message";

message.Attachments = new List<Attachment>();
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData("https://placeholdit.imgix.net/~text?txtsize=35&txt=image-data&w=120&h=120");
string url = "data:image/png;base64," + Convert.ToBase64String(imageBytes)
message.Attachments.Add(new Attachment { ContentUrl = url, ContentType = "image/png" });
await _client.Conversations.ReplyToActivityAsync(message);
like image 156
Jim Lewallen Avatar answered Oct 06 '22 10:10

Jim Lewallen