private async Task <DialogTurnResult> GetUsersTimezoneStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Context.Activity.Text != null)
            {
                stepContext.Context.Activity.Text = null;
                return(await stepContext.NextAsync(cancellationToken));
            }

            var userSelections = await UserSelectionsState.GetAsync(stepContext.Context, () => new UserSelections(), cancellationToken);

            await stepContext.Context.SendActivityAsync(
                MessageFactory.Text("Please select a valid time zone from the list and hit the 'Submit' button"),
                cancellationToken);

            var cardAttachment = TimezoneCard.Create(userSelections.CountryCode);
            var reply          = stepContext.Context.Activity.CreateReply();

            reply.Attachments = new List <Attachment> {
                cardAttachment
            };
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);

            return(await stepContext.PromptAsync(Constants.TimezonePrompt,
                                                 new PromptOptions
            {
                Prompt = new Activity
                {
                    Text = string.Empty,
                    Type = ActivityTypes.Message,
                }
            },
                                                 cancellationToken));
        }
Ejemplo n.º 2
0
        //second Step
        private async Task <DialogTurnResult> GetUsersTimezoneStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var userSelections = await UserSelectionsState.GetAsync(stepContext.Context, () => new UserSelections(), cancellationToken);

            var countryJson = JObject.Parse((string)stepContext.Result);

            if (countryJson.ContainsKey("country"))
            {
                userSelections.CountryCode = countryJson["country"].ToString();
            }

            await UserSelectionsState.SetAsync(stepContext.Context, userSelections, cancellationToken);

            var cardAttachment = TimezoneCard.Create(userSelections.CountryCode);
            var reply          = stepContext.Context.Activity.CreateReply();

            reply.Attachments = new List <Attachment> {
                cardAttachment
            };
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);

            return(await stepContext.PromptAsync("timezone",
                                                 new PromptOptions
            {
                Prompt = new Activity
                {
                    Text = string.Empty,
                    Type = ActivityTypes.Message,
                }
            },
                                                 cancellationToken));
        }