Esempio n. 1
0
        protected override async Task OnPromptAsync(ITurnContext turnContext, IDictionary <string, object> state, PromptOptions options, bool isRetry, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (turnContext == null)
            {
                throw new ArgumentNullException(nameof(turnContext));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!(options is GetEventOptions))
            {
                throw new Exception(nameof(options) + " should be GetEventOptions");
            }

            if (calendarService == null || userTimeZone == null)
            {
                GetEventOptions getEventOptions = (GetEventOptions)options;
                calendarService = getEventOptions.CalendarService;
                userTimeZone    = getEventOptions.TimeZone;
            }

            if (isRetry && options.RetryPrompt != null)
            {
                await turnContext.SendActivityAsync(options.RetryPrompt, cancellationToken).ConfigureAwait(false);
            }
            else if (options.Prompt != null)
            {
                await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        public async Task BasicGetEventPromptTest()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

            TestAdapter adapter = new TestAdapter()
                                  .Use(new AutoSaveStateMiddleware(convoState));

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var getEventPrompt = new GetEventPrompt("GetEventPrompt", defaultLocale: Culture.English);

            dialogs.Add(getEventPrompt);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var dc      = await dialogs.CreateContextAsync(turnContext, cancellationToken);
                var service = new MockCalendarService(MockCalendarService.FakeDefaultEvents());

                var results = await dc.ContinueDialogAsync();
                if (results.Status == DialogTurnStatus.Empty)
                {
                    var options = new GetEventOptions(service, mockUserTimeZone)
                    {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "Which event you are searching?"
                        },
                    };
                    await dc.PromptAsync("GetEventPrompt", options, cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var resolution = (IList <EventModel>)results.Result;
                    var reply      = MessageFactory.Text($"Get {resolution.Count} event");
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply("Which event you are searching?")
            .Send("today")
            .AssertReply(GetEventResponse())
            .StartTestAsync();
        }