1

i have a basic form. Depending on the choices of the user, it will direct it to various formflows. But i am unable to achieve this. It repeats first formFlow again and again in Microsoft BOT framework ?

//These are two forms that i have initiated. If a count is 1 then it must open first formflow otherwise the second formflow. internal static IDialog<General> MakeRootDialog() { return Chain.From(() => FormDialog.FromForm(General.BuildForm)); } internal static IDialog<ProfileForm> MakeRootDialog1() { return Chain.From(() => FormDialog.FromForm(ProfileForm.BuildForm)); } public async Task<HttpResponseMessage> Post([FromBody]Activity activity) { if (activity.Type == ActivityTypes.Message && General.count == 0) { await Conversation.SendAsync(activity, MakeRootDialog); General.count = 1; } else if(activity.Type == ActivityTypes.Message && General.count >= 1) { await Conversation.SendAsync(activity, MakeRootDialog1); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return response; } 
3
  • Can you include some code to understand what you are doing and why it's not working? It's hard to provide you an answer with the current details. Do you have a PromptChoice and based on the user selection, do you want to launch a FormFlow? From where do you want to switch between forms? Commented Oct 6, 2016 at 12:03
  • i have added the code above. Commented Oct 6, 2016 at 12:27
  • @EzequielJadib kindly see the code above that i just added Commented Oct 6, 2016 at 12:37

1 Answer 1

2

I was able to repro the problem but I'm still thinking how that could be solved using Chains in the MessageController.

My suggestion to unblock you is to move the "IF" logic for the Forms into a separate dialog. Something like the following:

Controller

public async Task<HttpResponseMessage> Post([FromBody]Activity activity) { if (activity.Type == ActivityTypes.Message) { await Conversation.SendAsync(activity, () => new RootDialog()); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return response; } 

RootDialog

[Serializable] public class RootDialog : IDialog<object> { public async Task StartAsync(IDialogContext context) { context.Wait(this.MessageReceivedAsync); } private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result) { if (General.count == 0) { General.count = 1; context.Call(FormDialog.FromForm<General>(General.BuildForm, FormOptions.PromptInStart), async (ctx, formResult) => ctx.Wait(this.MessageReceivedAsync)); } else if (General.count >= 1) { context.Call(FormDialog.FromForm<ProfileForm>(ProfileForm.BuildForm, FormOptions.PromptInStart), async (ctx, formResult) => ctx.Wait(this.MessageReceivedAsync)); } } } 

This is a personal opinion => I prefer to use Dialogs since once the bot start to grow it's easier to follow the logic and to separate the components.

Sign up to request clarification or add additional context in comments.

2 Comments

hey is it possible to return images in formflow on form completion stage? await context.PostAsync("Thankyou for filling form");// here rather than sending back text. can i just send some images in postAsync?
For sure!. The BotFramework has the concept of attachments. You can send an image as part of the reply message. Take a look to the Send Attachment sample for more info: github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/…. BTW, in that repo you will find a lot task-focused samples that I'm sure you will find useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.