Beispiel #1
0
        public async Task <DialogTurnResult> AfterUpdateAddress(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                if (state.AttendeesNameList.Any())
                {
                    state.FirstEnterFindContact = true;
                    return(await sc.BeginDialogAsync(nameof(FindContactDialog), options : sc.Options, cancellationToken : cancellationToken));
                }

                if (sc.Result != null)
                {
                    sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
                    var userInput = content != null?content.ToString() : sc.Context.Activity.Text;

                    if (state.EventSource != EventSource.Other)
                    {
                        if (userInput != null)
                        {
                            var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None)
                                           .Select(x => x.Trim())
                                           .Where(x => !string.IsNullOrWhiteSpace(x))
                                           .ToList();
                            state.AttendeesNameList = nameList;
                        }

                        state.FirstEnterFindContact = true;
                        return(await sc.BeginDialogAsync(nameof(FindContactDialog), options : sc.Options, cancellationToken : cancellationToken));
                    }
                    else
                    {
                        return(await sc.BeginDialogAsync(Actions.UpdateAddress, new UpdateAddressDialogOptions(UpdateAddressDialogOptions.UpdateReason.NotAnAddress), cancellationToken));
                    }
                }
                else
                {
                    return(await sc.NextAsync(cancellationToken : cancellationToken));
                }
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Beispiel #2
0
        public async Task <DialogTurnResult> AfterConfirmNameList(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context);

                // get name list from sc.result
                if (sc.Result != null)
                {
                    sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
                    var userInput = content != null?content.ToString() : sc.Context.Activity.Text;

                    // if is skip. set the name list to be myself only.
                    if (CreateEventWhiteList.IsSkip(userInput))
                    {
                        state.AttendeesNameList = new List <string>
                        {
                            CalendarCommonStrings.MyselfConst
                        };
                    }
                    else
                    if (state.EventSource != EventSource.Other)
                    {
                        if (userInput != null)
                        {
                            var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None)
                                           .Select(x => x.Trim())
                                           .Where(x => !string.IsNullOrWhiteSpace(x))
                                           .ToList();
                            state.AttendeesNameList = nameList;
                        }
                    }
                }

                if (state.AttendeesNameList.Any())
                {
                    if (state.AttendeesNameList.Count > 1)
                    {
                        var nameString = await GetReadyToSendNameListStringAsync(sc);

                        await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.BeforeSendingMessage, new StringDictionary()
                        {
                            { "NameList", nameString }
                        }));
                    }

                    // go to loop to go through all the names
                    state.ConfirmAttendeesNameIndex = 0;
                    return(await sc.ReplaceDialogAsync(Actions.LoopNameList, sc.Options, cancellationToken));
                }

                state.AttendeesNameList         = new List <string>();
                state.CurrentAttendeeName       = string.Empty;
                state.ConfirmAttendeesNameIndex = 0;
                return(await sc.EndDialogAsync());
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
        private async Task <DialogTurnResult> AfterConfirmNameListAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var options = sc.Options as FindContactDialogOptions;

                // get name list from sc.result
                if (sc.Result != null)
                {
                    sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
                    var userInput = content != null?content.ToString() : sc.Context.Activity.Text;

                    // if is skip. set the name list to be myself only.
                    if (CreateEventWhiteList.IsSkip(userInput))
                    {
                        state.MeetingInfo.ContactInfor.ContactsNameList = new List <string>
                        {
                            CalendarCommonStrings.MyselfConst
                        };
                    }
                    else
                    if (state.EventSource != EventSource.Other)
                    {
                        if (userInput != null)
                        {
                            var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None)
                                           .Select(x => x.Trim())
                                           .Where(x => !string.IsNullOrWhiteSpace(x))
                                           .ToList();
                            state.MeetingInfo.ContactInfor.ContactsNameList = nameList;
                        }
                    }
                }

                if (state.MeetingInfo.ContactInfor.ContactsNameList.Any())
                {
                    if (state.MeetingInfo.ContactInfor.ContactsNameList.Count > 1 && !(state.InitialIntent == CalendarLuis.Intent.CheckAvailability))
                    {
                        var nameString = await GetReadyToSendNameListStringAsync(sc, cancellationToken);

                        var activity = TemplateManager.GenerateActivityForLocale(FindContactResponses.BeforeSendingMessage, new
                        {
                            NameList = nameString
                        });
                        await sc.Context.SendActivityAsync(activity, cancellationToken);
                    }

                    // go to loop to go through all the names
                    state.MeetingInfo.ContactInfor.ConfirmContactsNameIndex = 0;
                    return(await sc.ReplaceDialogAsync(Actions.LoopNameList, sc.Options, cancellationToken));
                }

                // todo:
                state.MeetingInfo.ContactInfor.ContactsNameList         = new List <string>();
                state.MeetingInfo.ContactInfor.CurrentContactName       = string.Empty;
                state.MeetingInfo.ContactInfor.ConfirmContactsNameIndex = 0;
                return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptionsAsync(sc, ex, cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }