我正在使用 C# Bot Builder 开发一个机器人。
现在,我知道有很多关于如何处理链接对话框的例子。像 FacebookAuthDialog 或 ChainedEchoDialog。
我想要做什么:用户必须通过授权对话框,完成后,我想立即将用户放入“UserDialog”,在那里他可以使用所有需要他的身份验证的功能。
这是我的代码:
public static readonly IDialog<string> dialog = Chain
.PostToChain()
.Switch(
new Case<Message, IDialog<string>>((msg) =>
{
var userInfo = new StorageClient().GetUser(msg.From.Id);
if (userInfo != null && userInfo.Activated)
return false;
else
return true;
}, (ctx, msg) =>
{
return Chain.ContinueWith(new AuthenticationDialog(),
async (context, res) =>
{
var result = await res;
return Chain.Return($"You successfully activated your account.");
});
}),
new Case<Message, IDialog<string>>((msg) =>
{
var userInfo = new StorageClient().GetUser(msg.From.Id);
if (userInfo != null && userInfo.Activated)
return true;
else
return false;
}, (ctx, msg) =>
{
var service = new LuisService();
// User wants to login, send the message to Facebook Auth Dialog
return Chain.ContinueWith(new UserDialog(msg, service),
async (context, res) =>
{
return Chain.Return($"");
});
}),
new DefaultCase<Message, IDialog<string>>((ctx, msg) =>
{
return Chain.Return("Something went wrong.");
})
).Unwrap().PostToUser();
这种作品。我从 MessageController 调用此对话框
await Conversation.SendAsync(message, () => ManagingDialog.dialog);
但这感觉不对。每次对话完成时,我还必须调用此对话两次,因为当用户输入某些内容时,什么都不会发生,因为这只会启动对话。
我试图在 AuthenticationDialog 案例执行后放置另一个 ContinueWith,但我无法让它工作。
我真的很感谢一些代码片段的帮助。我完全一无所知。
问候