Microsoft Bot Receive attachments from user using FormFlow

社会主义新天地 提交于 2019-11-29 15:23:53
Ezequiel Jadib

Update

Support for attachments in FormFlow was added in https://github.com/Microsoft/BotBuilder/pull/2870

There is a sample located here that demonstrates how to accomplish this. For the form itself, you will need to look at ImagesForm.cs

---------

Currently this is not supported. After going through the BotBuilder code, the only workaround I could offer implies rebuilding the BotBuilder library code as you will have to make some updates in the FormDialog to hack it a bit to get the Attachment url.

If you want to try the workaround (again, is workaround, I haven't fully tested this and this could have other implications that I'm not aware of), get the BotBuilder code, find the FormDialog class and then replace these two lines with the following code:

var message = toBot != null ? (await toBot) : null;
var toBotText = message != null ? message.Text : null;
var toBotAttachments = message != null ? message.Attachments : null;

var stepInput = (toBotAttachments != null && toBotAttachments.Any()) ? toBotAttachments.First().ContentUrl : (toBotText == null) ? "" : toBotText.Trim();

What this workaround does is checking if the incoming message has attachments. If it has, then it discards the text and uses the ContentUrl of the first attachment. Then, in your Form model property, you will get the attachment url.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!