How to add C# waterfall dialog to Bot Composer

58 Views Asked by At

I have created the chatbot with bot framework composer, now as there are some limitations in the composer data manipulation gathered from adaptive cards I would like to create one dialog in bot framework C# version as a waterfall dialog. Is there a way to add waterfall dialog to the composer project with VS and then somehow invoke it. I have found the blog post about doing it the opposite way link but although I searched trough the internet I cannot find any help. Is there anyone who did it before? Is it possibly?

1

There are 1 best solutions below

0
piotr On

I've found an answer - according to the Composer docs (https://learn.microsoft.com/en-us/composer/how-to-create-custom-actions) it is possible to create a custom action. As per the sample below:

using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder.Dialogs;
using Newtonsoft.Json;

namespace Microsoft.Bot.Components.Samples.MultiplyDialog
{
    /// <summary>
    /// Custom command which takes takes 2 data bound arguments (arg1 and arg2) and multiplies them returning that as a databound result.
    /// </summary>
    public class MultiplyDialog : Dialog
    {
        [JsonConstructor]
        public MultiplyDialog([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
            : base()
        {
            // enable instances of this command as debug break point
            RegisterSourceLocation(sourceFilePath, sourceLineNumber);
        }

the action class inherits from "Dialog" class while waterfall dialog needs to inherit from "ComponentDialog". While evaluating the the "ComponentDialog" I found that it inherits from "DialogContainer" which also inherits from "Dialog" class. So it's possible to implement waterfall dialog similarly to custom actions as below:

using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using CustomWaterfallDialogs.Dialogs;

namespace CustomWaterfallDialogs
{

    public class DatePickerDialog : ComponentDialog
    {
        [JsonProperty("$kind")]
        public const string Kind = "DatePickerDialog";

        [JsonProperty("questionToAsk")]
        public StringExpression questionToAsk { get; set; }

        [JsonProperty("resultProperty")]
        public StringExpression ResultProperty { get; set; }

        [JsonConstructor]
        public DatePickerDialog([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) : base(nameof(DatePickerDialog))
        {
            AddDialog(new TextPrompt("AskForDueDateAsync", AskForDueDateValidator));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                DueDateAsync,
                FinishDialogStepAsync,
            }));

            InitialDialogId = nameof(WaterfallDialog);
        }