How to combine several dialogs?

Im working on a bot with C # Bot Builder.

Now, I know that there are quite a few examples of how to deal with conversations. Like FacebookAuthDialog or ChainedEchoDialog.

What I want to do: the user must go through the authorization dialog, and when this is done, I want to immediately put the user in "UserDialog", where he can use all the functions that need his authentication.

Here is my code:

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(); 

This type of work. I call this dialog from MessageController using

 await Conversation.SendAsync(message, () => ManagingDialog.dialog); 

But that does not seem right. I also have to call this dialog twice every time the dialog ends, because when the user enters something, nothing happens, since this only starts the dialog.

I tried putting another ContinueWith after doing Case AuthenticationDialog, but I could not get it to work.

I would really appreciate help in some code snippets. Im totally ignorant.

Hi

+7
c # botframework botbuilder
source share
1 answer

Here is an example from BotBuilder:

  public async Task SampleChain_Quiz() { var quiz = Chain .PostToChain() .Select(_ => "how many questions?") .PostToUser() .WaitToBot() .Select(m => int.Parse(m.Text)) .Select(count => Enumerable.Range(0, count).Select(index => Chain.Return($"question {index + 1}?").PostToUser().WaitToBot().Select(m => m.Text))) .Fold((l, r) => l + "," + r) .Select(answers => "your answers were: " + answers) .PostToUser(); using (var container = Build(Options.ResolveDialogFromContainer)) { var builder = new ContainerBuilder(); builder .RegisterInstance(quiz) .As<IDialog<object>>(); builder.Update(container); await AssertScriptAsync(container, "hello", "how many questions?", "3", "question 1?", "A", "question 2?", "B", "question 3?", "C", "your answers were: A,B,C" ); } } 

There is a good discussion on this topic at BotBuilder github

+3
source share

All Articles