/// <inheritdoc/>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            if (Card == null)
            {
                throw new ArgumentException($"A valid {nameof(Card)} is required for {Kind}.");
            }

            var activity = await Card.BindAsync(dc, dc.State).ConfigureAwait(false);

            if (activity?.Attachments?.Any() != true)
            {
                throw new InvalidOperationException($"Invalid activity. An attachment is required for {Kind}.");
            }

            Attachment attachment = activity.Attachments[0];

            var title           = Title.GetValueOrNull(dc.State);
            var height          = Height.GetValueOrNull(dc.State);
            var width           = Width.GetValueOrNull(dc.State);
            var completionBotId = CompletionBotId.GetValueOrNull(dc.State);

            var response = new TaskModuleResponse
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo
                    {
                        Title           = title,
                        Card            = attachment,
                        Height          = height,
                        Width           = width,
                        CompletionBotId = completionBotId,
                    },
                },
                CacheInfo = GetCacheInfo(dc),
            };

            var responseActivity          = CreateInvokeResponseActivity(response);
            ResourceResponse sendResponse = await dc.Context.SendActivityAsync(responseActivity, cancellationToken : cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(sendResponse, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc/>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            Activity activity = null;

            if (Card != null)
            {
                activity = await Card.BindAsync(dc, dc.State).ConfigureAwait(false);
            }

            if (activity?.Attachments?.Any() != true)
            {
                throw new InvalidOperationException($"Missing attachments in {Kind}.");
            }

            var title           = Title.GetValueOrNull(dc.State);
            var height          = Height.GetValueOrNull(dc.State);
            var width           = Width.GetValueOrNull(dc.State);
            var completionBotId = CompletionBotId.GetValueOrNull(dc.State);

            var response = new MessagingExtensionActionResponse
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo
                    {
                        Card            = activity.Attachments[0],
                        Height          = height,
                        Width           = width,
                        Title           = title,
                        CompletionBotId = completionBotId
                    },
                },
            };

            var invokeResponse   = CreateInvokeResponseActivity(response);
            var resourceResponse = await dc.Context.SendActivityAsync(invokeResponse, cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(resourceResponse, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        /// <inheritdoc/>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            string url = Url.GetValueOrNull(dc.State);

            if (string.IsNullOrEmpty(url))
            {
                throw new InvalidOperationException($"Missing {nameof(Url)} for {Kind}.");
            }

            var title  = Title.GetValueOrNull(dc.State);
            var height = Height.GetValueOrNull(dc.State);
            var width  = Width.GetValueOrNull(dc.State);

            var fallbackUrl     = FallbackUrl.GetValueOrNull(dc.State);
            var completionBotId = CompletionBotId.GetValueOrNull(dc.State);

            var response = new TaskModuleResponse
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo
                    {
                        Title           = title,
                        Url             = url,
                        FallbackUrl     = fallbackUrl,
                        Height          = height,
                        Width           = width,
                        CompletionBotId = completionBotId,
                    },
                },
                CacheInfo = GetCacheInfo(dc),
            };

            var responseActivity          = CreateInvokeResponseActivity(response);
            ResourceResponse sendResponse = await dc.Context.SendActivityAsync(responseActivity, cancellationToken : cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(sendResponse, cancellationToken : cancellationToken).ConfigureAwait(false));
        }