// Called when the task module is fetched for an action
        public async Task <MessagingExtensionActionResponse> HandleMessagingExtensionFetchTaskAsync(ITurnContext turnContext, MessagingExtensionAction query)
        {
            var emptyRequest = new ConsultingRequestDetails();
            ConsultingDataService dataService = new ConsultingDataService();

            emptyRequest.possibleProjects = await dataService.GetProjects("");

            IEnumerable <TeamsChannelAccount> members = await TeamsInfo.GetMembersAsync(turnContext);

            emptyRequest.possiblePersons = members.Select((w) => new Person
            {
                name  = w.Name,
                email = w.Email
            })
                                           .ToList();

            var card = await AddToProjectCard.GetCardAsync(turnContext, emptyRequest);

            var response = new Microsoft.Bot.Schema.Teams.TaskModuleContinueResponse()
            {
                Type  = "continue",
                Value = new TaskModuleTaskInfo()
                {
                    Title = "Select a sample",
                    Card  = card.ToAttachment()
                }
            };

            return(new MessagingExtensionActionResponse
            {
                Task = response
            });
        }
Beispiel #2
0
        public static async Task <ConsultingRequestDetails> ExecuteQuery(IConfiguration configuration, ILogger logger, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var result = new ConsultingRequestDetails();

            try
            {
                // Create the LUIS settings from configuration.
                var luisApplication = new LuisApplication(
                    configuration["LuisAppId"],
                    configuration["LuisAPIKey"],
                    "https://" + configuration["LuisAPIHostName"]
                    );

                var recognizer = new LuisRecognizer(luisApplication);

                // The actual call to LUIS
                var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken);

                var(intent, score) = recognizerResult.GetTopScoringIntent();

                // Now based on the intent, fill in the result as best we can
                switch (intent)
                {
                case "Toast":
                {
                    result.intent = Intent.Toast;
                    break;
                }

                case "Roast":
                {
                    result.intent = Intent.Roast;
                    break;
                }

                default:
                {
                    result.intent = Intent.Unknown;
                    break;
                }
                }
            }
            catch (Exception e)
            {
                logger.LogWarning($"LUIS Exception: {e.Message} Check your LUIS configuration.");
            }

            return(result);
        }
        public static AdaptiveCard GetCard(ConsultingRequestDetails value)
        {
            var project = value.project;
            var card    = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            card.Body.Add(new AdaptiveTextBlock($"You billed {value.workHours} hours to {project.Client.Name}")
            {
                Weight = AdaptiveTextWeight.Default,
                Size   = AdaptiveTextSize.Large,
            });

            // Display details in a fact set
            var factSet = new AdaptiveFactSet();

            factSet.Facts.Add(new AdaptiveFact("Client", project.Client.Name));
            factSet.Facts.Add(new AdaptiveFact("Project", project.Name));
            factSet.Facts.Add(new AdaptiveFact("Hours", value.workHours.ToString()));
            factSet.Facts.Add(new AdaptiveFact("Date worked", value.workDate));

            card.Body.Add(new AdaptiveColumnSet()
            {
                Columns = new List <AdaptiveCards.AdaptiveColumn>()
                {
                    new AdaptiveColumn()
                    {
                        Width = "15%",
                        Items = new List <AdaptiveElement>()
                        {
                            new AdaptiveImage(value.project.Client.LogoUrl)
                        }
                    },
                    new AdaptiveColumn()
                    {
                        Width = "85%",
                        Items = new List <AdaptiveElement>()
                        {
                            factSet
                        }
                    },
                }
            });

            return(card);
        }
        public static async Task <ConsultingRequestDetails> ExecuteQuery(IConfiguration configuration, ILogger logger, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var result = new ConsultingRequestDetails();

            try
            {
                // Create the LUIS settings from configuration.
                var luisApplication = new LuisApplication(
                    configuration["LuisAppId"],
                    configuration["LuisAPIKey"],
                    "https://" + configuration["LuisAPIHostName"]
                    );
                var recognizer = new LuisRecognizer(luisApplication);

                // The actual call to LUIS
                var recognizerResult = await recognizer.RecognizeAsync(turnContext, cancellationToken);

                var(intent, score) = recognizerResult.GetTopScoringIntent();

                // Get all the possible values for each entity from the Entities JObject
                // (GetEntityValueOptions is an extension method, see below)
                var personNameValues  = recognizerResult.GetPossibleEntityValues <string>("personName");
                var projectNameValues = recognizerResult.GetPossibleEntityValues <string>("projectName");
                var dateTimeValues    = recognizerResult.GetPossibleEntityValues <string>("datetime");
                var dayWorkedValues   = recognizerResult.GetPossibleEntityValues <string>("day_worked");
                if (dayWorkedValues.Count == 0)
                {
                    dayWorkedValues = dateTimeValues;
                }
                var timeWorkedValues = recognizerResult.GetPossibleEntityValues <string>("time_worked");
                if (timeWorkedValues.Count == 0)
                {
                    timeWorkedValues = dateTimeValues;
                }

                // Now based on the intent, fill in the result as best we can
                switch (intent)
                {
                case "AddPersonToProject":
                {
                    result.intent      = Intent.AddToProject;
                    result.personName  = personNameValues?.FirstOrDefault();
                    result.projectName = projectNameValues?.FirstOrDefault();
                    break;
                }

                case "BillToProject":
                {
                    result.intent      = Intent.BillToProject;
                    result.projectName = projectNameValues?.FirstOrDefault();
                    result.workDate    = TryExtractWorkDate(dayWorkedValues);
                    result.workHours   = TryExtractWorkHours(timeWorkedValues);
                    break;
                }

                default:
                {
                    result.intent = Intent.Unknown;
                    break;
                }
                }
            }
            catch (Exception e)
            {
                logger.LogWarning($"LUIS Exception: {e.Message} Check your LUIS configuration.");
            }

            return(result);
        }
        public static async Task<AdaptiveCard> GetCardAsync(ITurnContext turnContext, ConsultingRequestDetails requestDetails)
        {
            var templateJson = String.Empty;
            var assembly = Assembly.GetEntryAssembly();
            var resourceStream = assembly.GetManifestResourceStream("ConsultingBot.Cards.AddToProjectCard.json");
            using (var reader = new StreamReader(resourceStream, Encoding.UTF8))
            {
                templateJson = await reader.ReadToEndAsync();
            }

            requestDetails.monthZero = GetMonthFromNow(0).ToString("MMMM, yyyy");
            requestDetails.monthOne = GetMonthFromNow(1).ToString("MMMM, yyyy");
            requestDetails.monthTwo = GetMonthFromNow(2).ToString("MMMM, yyyy");
            var dataJson = JsonConvert.SerializeObject(requestDetails);

            var transformer = new AdaptiveTransformer();
            var cardJson = transformer.Transform(templateJson, dataJson);

            var result = AdaptiveCard.FromJson(cardJson).Card;
            return result;
        }