0

I've a sample bot using Microsoft's .NET Bot framework.

I would like to create a menu to Facebook messenger.

What text do I need to append and how to catch the option that the user selected?

This is what I have right now:

strReplyMessage.Append($"Hello, I am **TestBot** Bot");
strReplyMessage.Append($"\n");
strReplyMessage.Append($"You can say anything");
strReplyMessage.Append($"\n");
strReplyMessage.Append($"to me and I will repeat it back");
strReplyMessage.Append($"\n\n");
strReplyMessage.Append($"What is your name?");

Any clue?

stuartd
  • 70,509
  • 14
  • 132
  • 163
VAAA
  • 14,531
  • 28
  • 130
  • 253
  • Have you considered using a [PromptChoice dialog](https://docs.botframework.com/en-us/csharp/builder/sdkreference/dc/df9/class_microsoft_1_1_bot_1_1_builder_1_1_dialogs_1_1_prompt_dialog_1_1_prompt_choice.html)? – stuartd Jan 11 '17 at 17:13
  • Do you know how can I use it? I dont see a sample in the documentation – VAAA Jan 11 '17 at 17:18
  • Yeah, there's not much on it. SHouldn't be too hard though, you pass a style and a list of optioms.. – stuartd Jan 11 '17 at 17:27

2 Answers2

0

Here you will find an example on how to use a PromptChoice.

I pasted the below for your convenience.

How to call it

PromptDialog.Choice(context, this.OnOptionSelected, new List<string>() { FlightsOption, HotelsOption }, "Are you looking for a flight or a hotel?", "Not a valid option", 3);

How to get the selected option

        private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result)
        {
            try
            {
                string optionSelected = await result;

                switch (optionSelected)
                {
                    case FlightsOption:
                        context.Call(new FlightsDialog(), this.ResumeAfterOptionDialog);
                        break;

                    case HotelsOption:
                        context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
                        break;
                }
            }
            catch (TooManyAttemptsException ex)
            {
                await context.PostAsync($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");

                context.Wait(this.MessageReceivedAsync);
            }
        }
Ezequiel Jadib
  • 14,767
  • 2
  • 38
  • 43
  • Im trying to add Prompt Dialog inside my public async Task PostTest([FromBody]Activity activity), but I dont know how to get context. Any clue? – VAAA Jan 11 '17 at 20:15
  • do it on a dialog, not in the controller. Check https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-MultiDialogs for some basic guidance around dialogs. – Ezequiel Jadib Jan 11 '17 at 20:47
0

Alternative you can adding a KeyboardCard.

KeyboardCard (string text, IList< CardAction > buttons)

Parameters

  • text The keyboard text.
  • buttons The buttons in keyboard.
Lars
  • 9,976
  • 4
  • 34
  • 40