2

I'm building a bot with the Microsoft Bot Framework, V3, in C# and trying to have the Dialog start and "welcome" the user with instructions before they enter any input. I would also like the Dialog to repeat every time that the user completes the form.

I'm attempting to use the FormFlow options: FormOptions.PromptInStart but it is still having the welcome message appear only after they enter some input. Not sure if this is deprecated with V1 or I'm just not doing it right. Any advice??

My classes are as below:

MessagesController:

 internal static IDialog<MyClass> MakeRootDialog() { return Chain.From(() => FormDialog.FromForm(MyClass.BuildForm, options: FormOptions.PromptInStart)) .Do(async (context, order) => {//some actions here } }); } 

MyClass.cs :

 [Serializable] public class MyClassDialog : IDialog<object> { public async Task StartAsync(IDialogContext context) { context.Wait(MessageReceivedAsync); } public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument) { var message = await argument; await context.PostAsync("You said: " + message.Text); context.Wait(MessageReceivedAsync); } } 

MyClassDialog.cs :

public class MyClass { public static IForm<MyClass> BuildForm() { OnCompletionAsyncDelegate<MyClass> processOrder = async (context, state) => { await context.PostAsync("We are currently filing your order....."); }; return new FormBuilder<MyClass>() .Message("Welcome to my bot!") //some actions here .Confirm(//more actions here) .AddRemainingFields() .Message("Thanks for providing your inputs") .OnCompletion(processOrder) .Build(); } }; 

3 Answers 3

1

How do you implement Post method? I think you dont have problem in form but in Post method.

This code work for me.

public async Task<HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message || activity.Type == ActivityTypes.ConversationUpdate) { Conversation.SendAsync(activity, MakeRootDialog); { } 

Because if user connect, ActivityType is ConversationUpdate, no message. You must call MakeRootDialog when activity.Type == ActivityTypes.ConversationUpdate too.

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

Comments

1

you can check message.Type == ActivityTypes.ConversationUpdate and message.MembersAdded.Any(o => o.Id == message.Recipient.Id)
ref from BotBuilder-Samples/CSharp/demo-ContosoFlowers/

private async Task HandleSystemMessage(Activity message) { if (message.Type == ActivityTypes.DeleteUserData) { // Implement user deletion here // If we handle user deletion, return a real message } else if (message.Type == ActivityTypes.ConversationUpdate) { if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id)) { var RootDialog_Welcome_Message = "welcome! i'm rainmaker"; var reply = message.CreateReply(RootDialog_Welcome_Message); ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl)); await connector.Conversations.ReplyToActivityAsync(reply); } } else if (message.Type == ActivityTypes.ContactRelationUpdate) { // Handle add/remove from contact lists // Activity.From + Activity.Action represent what happened } else if (message.Type == ActivityTypes.Typing) { // Handle knowing tha the user is typing } else if (message.Type == ActivityTypes.Ping) { } } 

Comments

0

are you testing using the emulator?

I've had a similar experience and it seems it depends on the client. I'm getting the same experience you have in my local emulator but I'm seeing the welcome message just fine when I run it through the webchat client: https://docs.botframework.com/en-us/support/embed-chat-control2/

I added a screendump from my webchat: Welcome message in webchat

1 Comment

Yes, we were testing with emulator, but were having the same problem in WebChat. Realized it was an issue with our Dialog class.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.