Beispiel #1
0
        private async Task <DialogTurnResult> CreateAppointmentStepAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            stepContext.Values["endTime"] = (string)stepContext.Result;

            var tokenResponse = stepContext.Options as TokenResponse;
            var start         = new DateTimeTimeZone
            {
                DateTime = (string)stepContext.Values["startTime"],
                TimeZone = "Pacific Standard Time"
            };

            var end = new DateTimeTimeZone
            {
                DateTime = (string)stepContext.Values["endTime"],
                TimeZone = "Pacific Standard Time"
            };

            var title = (string)stepContext.Values["title"];
            await SimpleGraphClient.GetAuthenticatedClient(tokenResponse.Token).SetAppointment(title, start, end);

            await stepContext.Context.SendActivityAsync("Event created",
                                                        cancellationToken : cancellationToken);

            return(await stepContext.EndDialogAsync());
        }
Beispiel #2
0
        private async Task <DialogTurnResult> ProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result != null)
            {
                // We do not need to store the token in the bot. When we need the token we can
                // send another prompt. If the token is valid the user will not need to log back in.
                // The token will be available in the Result property of the task.
                var tokenResponse = stepContext.Result as TokenResponse;

                // If we have the token use the user is authenticated so we may use it to make API calls.
                if (tokenResponse?.Token != null)
                {
                    var command = ((string)stepContext.Values["command"] ?? string.Empty).ToLowerInvariant();
                    var events  = await SimpleGraphClient.GetAuthenticatedClient(tokenResponse.Token).GetCalendarEvents();

                    var groupevents = await SimpleGraphClient.GetAuthenticatedClient(tokenResponse.Token).GetGroupCalendarEvents();

                    if (command == "mycalendar")
                    {
                        string eventsFormatted = string.Join("\n",
                                                             events.Select(s => $"- {s.Subject} from {DateTime.Parse(s.Start.DateTime).ToShortTimeString()} till {DateTime.Parse(s.End.DateTime).ToShortTimeString()}")
                                                             .ToList());

                        await stepContext.Context.SendActivityAsync("You have the following events: \n" + eventsFormatted,
                                                                    cancellationToken : cancellationToken);
                    }
                    else if (command.StartsWith("groupcalendar"))
                    {
                        string groupeventsFormatted = string.Join("\n",
                                                                  groupevents.Select(s => $"- {s.Subject} from {DateTime.Parse(s.Start.DateTime).ToShortTimeString()} till {DateTime.Parse(s.End.DateTime).ToShortTimeString()}")
                                                                  .ToList());

                        await stepContext.Context.SendActivityAsync("Your group have the following events: \n" + groupeventsFormatted,
                                                                    cancellationToken : cancellationToken);
                    }

                    else if (command.StartsWith("setappointment"))
                    {
                        return(await stepContext.BeginDialogAsync(nameof(AppointmentInfoDialog), tokenResponse, cancellationToken));
                    }
                    else if (command.StartsWith("create group calendar"))
                    {
                        await SimpleGraphClient.GetAuthenticatedClient(tokenResponse.Token).CreateGroupCalendar();

                        await stepContext.Context.SendActivityAsync("DEMO-GROUP-CALENDAR created \n",
                                                                    cancellationToken : cancellationToken);
                    }
                    else
                    {
                        // await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), cancellationToken);
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Oops! Thats not a valid entry"), cancellationToken);
                    }
                }
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("We couldn't log you in. Please try again later."), cancellationToken);
            }

            return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
        }