Send an image rather than a link

后端 未结 2 1324
有刺的猬
有刺的猬 2020-12-06 06:32

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

2条回答
  •  忘掉有多难
    2020-12-06 07:32

    You should be able to use something like this:

    var message = activity.CreateReply("");
    message.Type = "message";
    
    message.Attachments = new List();
    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);
    

提交回复
热议问题