如何在Bot Framework中将活动传递给formbuilder类

时间:2017-05-19 14:30:18

标签: bots botframework formbuilder

我在LUIS Dialog类下面,我将它重定向到formbuilder类,我想将一个context.Activity传递给我的formbuilder方法,它位于另一个类之后,就在代码之后给出。如何做到这一点?< / p>

public class LUISManager : LuisDialog<object>
{
    [LuisIntent("BookFlight")]
    public async Task BookFlight(IDialogContext context, LuisResult result)
    {    
        //context.Activity       
        FlightBooking cb = new FlightBooking();
        BuildFormDelegate<FlightBooking> MakeFlightBookingForm = FlightBooking.BuildForm;
        var flightBooking = new FormDialog<FlightBooking>(cb, MakeFlightBookingForm, FormOptions.PromptInStart, null);
        context.Call<FlightBooking>(flightBooking, FlightBookingComplete);
    }
}

[Serializable]
public class FlightBooking
{
public static IForm<FlightBooking> BuildForm()
{
    return new FormBuilder<FlightBooking>().Message("Tell me meeting details!")
    .Field(nameof(title))
    .Field(nameof(StartDate))//, validate: ValidateStartDate
    .Field(nameof(EntryTime), validate:ValidateCallTime)
    .Build();
}
},

我知道我们可以通过&#34; IDialogContext context&#34; BuildForm方法中的参数,但如何从BuildFormDelegate

传递它

1 个答案:

答案 0 :(得分:0)

将构造函数更改为:

public static IForm<FlightBooking> BuildForm(IDialogContext context)
{}

然后你可以使用lambda表达式:

BuildFormDelegate<FlightBooking> MakeFlightBookingForm = ()=>FlightBooking.BuildForm(context);