2016-10-10 42 views
0

我有这段代码。对话链问题(传递消息)

public class HotelBotDialog 
{ 

    public static readonly IDialog<string> dialog = Chain.PostToChain() 
     .Select(msg => msg.Text) 
     .Switch(
      new RegexCase<IDialog<string>>(new Regex("^hi", RegexOptions.IgnoreCase), (context, txt) => 
      { 
       return Chain.ContinueWith(new GreetingDialog(), AfterGreetingContinuation); 
      }), 
      new DefaultCase<string, IDialog<string>>((context, txt) => 
      { 
       return Chain.ContinueWith(FormDialog.FromForm(RoomReservation.BuildForm), AfterGreetingContinuation);     
      })) 
.Unwrap() 
.PostToUser(); 

    private async static Task<IDialog<string>> AfterGreetingContinuation(IBotContext context, IAwaitable<object> res) 
    { 
     var token = await res; 
     var name = "User"; 
     context.UserData.TryGetValue<string>("Name", out name); 
     return Chain.Return($"Thank you for using the hotel bot: {name}"); 
    } 
} 

}

这将工作,但问题是,每当我陷入了“默认情况下,”我需要在第二个条目,以揭开序幕我的形式进入。所以这是对话框如下

我:测试 BOT: 我:Test2的 BOT:欢迎您到酒店机器人......等等等等

我要的是

我:测试 机器人:欢迎来到酒店的机器人...

我会认为有什么问题,我没有通过原来的消息或什么东西。

有人可以帮忙吗?

回答

1

FormDialog.FromForm方法有一个接收FormOptions的重载。该枚举的其中一个值是PrompInStart,它基本上可以做你想要的;马上开始形式。

如果您没有为FormOptions提供任何值,它将默认为None,然后FormDialog只是在那里等待一条新消息。

在做那个(也linked)的BotBuilder逻辑:

if (this._options.HasFlag(FormOptions.PromptInStart)) 
{ 
    await MessageReceived(context, null); 
} 
else 
{ 
    context.Wait(MessageReceived); 
} 

因此,要解决问题,改变你的实例的形式方式:

FormDialog.FromForm(RoomReservation.BuildForm, FormOptions.PromptInStart) 

公告FormOptions.PromptInStart结尾处的

+0

非常感谢!这就是诀窍! – Matt