问题
I'm Designing a Bot using FormFlow in which one of the input will be asking user to attach a file to proceed further. I Can see below link addresses the similiar problem. https://github.com/Microsoft/BotBuilder/issues/570
The solution provided in the link is to use custom IRecognizer or as below
a) Put it into a private field/property that is not exposed to FormFlow.
b) Put it in as the value of field that is exposed to form flow.
c) Use the private property to dynamically generate a field that allows choosing between them.
I'm naive to the Bot Framework. Are there any examples to implement this on receiving the attachment from customer using FormFlow .
Below is my code snippet
enter code here
[Serializable]
public class DocBot
{
[Prompt("What's your name?")]
public string Name { get; set; }
[Prompt("Hey {&} , Choose the options below? {||}")]
public Service? shaun;
[Prompt("Attach the Document required for further processing?")]
public string Document { get; set; }
-- Need Suggestion on receiving documents attachment from the user here
[Prompt("What is your Job Title there?")]
public string JobTitle { get; set; }
[Prompt("What's the best number to contact you on?")]
public string Phone { get; set; }
public enum Service
{
Consultancy, Support, ProjectDelivery, Unknown
}
public static IForm<DocBot> BuildEnquiryForm()
{
return new FormBuilder<DocBot>()
.Message("Welcome to Doc BOT!!!")
.Field(nameof(Name))
// .Field(nameof(Document))
-- Need Suggestion on receiving documents attachment from the user here
.Build();
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/41853523/microsoft-bot-receive-attachments-from-user-using-formflow