How to receive an image send by users?

ぐ巨炮叔叔 提交于 2019-12-04 22:55:47

You're so close! Once the user uploads the photo, you can access it in the next Waterfall step with stepContext.Result:

As you can see, the type is Microsoft.Bot.Schema.Attachment, so change your IncidentFile to:

using Microsoft.Bot.Schema;

namespace <your-namespace>
{
    public class IncidentFile
    {
        public string Name { get; set; }
        public Attachment Photo { get; set; }
    }
}

You save that information in the step following the upload step with something like:

// Load the IncidentFile
var incidentFile = await IncidentFileAccessor.GetAsync(stepContext.Context);
// Save the photo
incidentFile.Photo = ((List<Attachment>)stepContext.Result)[0];
await IncidentFileAccessor.SetAsync(stepContext.Context, incidentFile);

Result:

References

  • C# Samples. I'd link to specific ones, but we're about to delete some and reorganize this repo. However, look at:
    • Basic Bot (soon to be Core Bot) - Good for figuring out how to use user profiles
    • Handling Attachments - General Attachment handling
  • Attachment Class
  • AttachmentPrompt Class
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!