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
c # botframework botbuilder
Eiren
source share