Exemple #1
0
        private async Task <DialogTurnResult> ProcessStep2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse != 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.

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

                    var command = parts[0];

                    if (command == "me")
                    {
                        await OAuthHelpers.ListMeAsync(stepContext.Context, tokenResponse);
                    }
                    else if (command.StartsWith("send"))
                    {
                        await OAuthHelpers.SendMailAsync(stepContext.Context, tokenResponse, parts[1]);
                    }
                    else if (command.StartsWith("recent"))
                    {
                        await OAuthHelpers.ListRecentMailAsync(stepContext.Context, tokenResponse);
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), 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));
        }
        private async Task <DialogTurnResult> ProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result != null)
            {
                // 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 parts = ((string)stepContext.Values["command"] ?? string.Empty).ToLowerInvariant().Split(' ');

                    var command = parts[0];

                    if (command == "me")
                    {
                        await OAuthHelpers.ListMeAsync(stepContext.Context, tokenResponse);

                        //return await stepContext.NextAsync();
                    }

                    else
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), cancellationToken);

                        return(await stepContext.NextAsync());
                    }
                }
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("We couldn't log you in. Please try again later."), cancellationToken);
            }

            return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
        }
        private async Task <DialogTurnResult> showAdaptiveCardAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if ((stepContext.Context.Activity.Text != null) || (stepContext.Context.Activity.Value != null))
            {
                // The token will be available in the Result property of the task.
                var tokenResponse = stepContext.Result as TokenResponse;

                List <Microsoft.Graph.User> users = new List <Microsoft.Graph.User>();
                var list = new List <Tuple <string, string> >();
                Dictionary <string, string> _teamsa = new Dictionary <string, string>();
                users = await OAuthHelpers.ListMeAsync(stepContext.Context, tokenResponse);

                try
                {
                    foreach (Microsoft.Graph.User u in users)
                    {
                        string dname = u.DisplayName;
                        string sname = u.Surname;
                        try
                        {
                            if (dname == null)
                            {
                                dname = "Test";
                            }
                            if (sname == null)
                            {
                                sname = "Test";
                            }
                        }
                        catch (Exception e) { }
                        //_teamsa.Add((JsonConvert.DeserializeObject(u.DisplayName.ToString())), (JsonConvert.DeserializeObject<Microsoft.Graph.User>(u.Surname.ToString())));
                        list.Add(Tuple.Create(dname, sname));
                        _teamsa.Add(dname, sname);
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                }
                List <string> _teamsType = new List <string>
                {
                    { "Public" },
                    { "Private" }
                };
                List <string> _teamsClassification = new List <string>
                {
                    { "Internal" },
                    { "External" },
                    { "Business" },
                    { "Protected" },
                    { "Important" },
                    { "Personal" }
                };

                //var choicesTeamOwners = _teamsa.Select(s => new AdaptiveChoice { Title = s.Key, Value = s.Key }).ToList();
                var choicesType = _teamsType.Select(s => new AdaptiveChoice {
                    Title = s, Value = s
                }).ToList();
                var choicesClassification = _teamsClassification.Select(s => new AdaptiveChoice {
                    Title = s, Value = s
                }).ToList();
                try
                {
                    var card = new AdaptiveCard
                    {
                        Version = new AdaptiveSchemaVersion(1, 0),
                        Body    =
                        {
                            new AdaptiveTextBlock("Team Name"),
                            new AdaptiveTextInput
                            {
                                Id = "Teamname",
                            },
                            new AdaptiveTextBlock("Description"),
                            new AdaptiveTextInput
                            {
                                Id = "Description",
                            },
                            new AdaptiveTextBlock("Team Owners"),
                            new AdaptiveChoiceSetInput
                            {
                                Choices       = choicesType,
                                Id            = "TeamOwners",
                                Style         = AdaptiveChoiceInputStyle.Compact,
                                IsMultiSelect = false
                            },
                            new AdaptiveTextBlock("Type"),
                            new AdaptiveChoiceSetInput
                            {
                                Choices       = choicesType,
                                Id            = "Type",
                                Style         = AdaptiveChoiceInputStyle.Compact,
                                IsMultiSelect = false
                            },
                            new AdaptiveTextBlock("Classification"),
                            new AdaptiveChoiceSetInput
                            {
                                Choices       = choicesClassification,
                                Id            = "Classification",
                                Style         = AdaptiveChoiceInputStyle.Compact,
                                IsMultiSelect = false
                            }
                        },
                        Actions = new List <AdaptiveAction>
                        {
                            new AdaptiveSubmitAction
                            {
                                Title = "Create Team",
                                Type  = "Action.Submit"
                            }
                        }
                    };

                    return(await stepContext.PromptAsync($"{ nameof(SiteRequestDialog)}.ShowCard",
                                                         new PromptOptions
                    {
                        // Choices = ChoiceFactory.ToChoices(_teamsa.Select(pair => pair.Value).ToList()),
                        Prompt = (Activity)MessageFactory.Attachment(new Attachment
                        {
                            ContentType = AdaptiveCard.ContentType,
                            Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card))
                        })
                    },
                                                         cancellationToken));
                }
                catch (Exception e)
                { e.ToString(); }
                return(await stepContext.NextAsync());
            }
            else
            {
                return(await stepContext.EndDialogAsync());
            }
        }