Beispiel #1
0
        private async Task FindTopicExpert(ITurnContext turnContext, RecognizerResult luisResults)
        {
            var    topic      = LUISDataUtilities.GetEntityAsString(luisResults, "Topic");
            string topSenders = string.Empty;

            if (topic != null && topic.Length > 0)
            {
                await turnContext.SendActivityAsync(string.Format("You seem to be looking for an someone who can help you with {0}. Let me see who I can find.\n", topic));

                //var tagRecipients = GraphAnalysisBusinessLogic.GetTopicRecipients(topic, this);

                int limit = 10;
                //var tagSenders = GraphAnalysisBusinessLogic.GetTopicSenders(topic, this);

                var tagSenderQueryResult = GraphAnalysisBusinessLogic.GetTopicSendersWithSentValues(topic, this);

                // This sorts descending so the strongest sender appears first
                var tagSenders = tagSenderQueryResult.ToList();
                tagSenders.Sort((kvp1, kvp2) => kvp2.Value.CompareTo(kvp1.Value));

                StringBuilder sb      = new StringBuilder();
                int           counter = 0;
                if (tagSenders.Count < limit)
                {
                    limit = tagSenders.Count;
                }

                foreach (var tagSender in tagSenders)
                {
                    //Add commas and "and"
                    if (counter > 0)
                    {
                        // Only take the top few
                        if (counter == limit)
                        {
                            break;
                        }

                        if (counter == (limit - 1))
                        {
                            if (limit > 2)
                            {
                                sb.Append(", and ");
                            }
                            else
                            {
                                sb.Append(" and ");
                            }
                        }
                        else
                        {
                            sb.Append(", ");
                        }
                    }

                    sb.Append(tagSender.Key);
                    counter++;
                }

                topSenders = sb.ToString();

                await turnContext.SendActivityAsync(string.Format("The people who send the most communication on the topic of {0} are {1}.\n", topic, topSenders));
            }
            else
            {
                await turnContext.SendActivityAsync("You seem to be looking for an someone who can help you, but I could not determine the topic of interest. Consider asking a question like \"Who can help me with privacy?\" and I will try to find people who communicate about that topic.\n");
            }

            //if (expert != null && expert.Length > 0)
            //{
            //    await turnContext.SendActivityAsync(String.Format("You seem to be looking for an someone who can help you with {0}. You might want to contact {1}.\n", topic, expert));
            //}
            //else
            //{
            //    await turnContext.SendActivityAsync(String.Format("You seem to be looking for an someone who can help you with {0}.\n", topic));
            //}
        }
Beispiel #2
0
        /// <summary>
        /// Run every turn of the conversation. Handles orchestration of messages.
        /// </summary>
        /// <param name="turnContext">Bot Turn Context.</param>
        /// <param name="cancellationToken">Task CancellationToken.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var activity = turnContext.Activity;

            // Create a dialog context
            var dc = await Dialogs.CreateContextAsync(turnContext);

            if (activity.Type == ActivityTypes.Message)
            {
                // Perform a call to LUIS to retrieve results for the current activity message.
                var luisResults = await _services.LuisServices[LuisConfiguration].RecognizeAsync(dc.Context, cancellationToken);

                // If any entities were updated, treat as interruption.
                // For example, "no my name is tony" will manifest as an update of the name to be "tony".
                var topIntent = luisResults?.GetTopScoringIntent();

                if (topIntent != null && topIntent.HasValue && topIntent.Value.intent != "None")
                {
                    switch (topIntent.Value.intent)
                    {
                    case GetDocumentsForTagIntent:
                        var topic = LUISDataUtilities.GetEntityAsString(luisResults, "Topic");
                        if (topic != null && topic.Length > 0)
                        {
                            await turnContext.SendActivityAsync(string.Format("You seem to be looking documents associated with {0}. Let me see what I can find.\n", topic));

                            var documentsGraphModel = GraphAnalysisBusinessLogic.GetDocumentsForTag(this, topic);
                            if (documentsGraphModel.Count > 0)
                            {
                                await turnContext.SendActivityAsync(string.Format("I found the following documents associated with {0}:", topic));

                                var reply = turnContext.Activity.CreateReply();
                                reply.Attachments = new List <Attachment>();

                                //Put the most recent documents at the head of the list
                                //documentsGraphModel.Reverse();
                                foreach (var document in documentsGraphModel)
                                {
                                    //    var attachment = new Attachment
                                    //    {
                                    //        ContentUrl = string.Format("{0}{1}/{2}?web=1", document.properties.library[0].value, document.properties.path[0].value, document.properties.name[0].value),
                                    //        Name = document.properties.name[0].value,
                                    //    };
                                    //    reply.Attachments.Add(attachment);

                                    //await turnContext.SendActivityAsync(string.Format("{1}{2}/{3}?web=1", document.properties.name[0].value, document.properties.library[0].value, document.properties.path[0].value, document.properties.name[0].value).Replace(" ", "%20"));

                                    List <CardAction> cardButtons = new List <CardAction>();
                                    CardAction        plButton    = new CardAction()
                                    {
                                        Value = string.Format("{1}{2}/{3}?web=1", document.properties.name[0].value, document.properties.library[0].value, document.properties.path[0].value, document.properties.name[0].value).Replace(" ", "%20"),
                                        Type  = "openUrl",
                                        Title = document.properties.name[0].value,
                                    };
                                    cardButtons.Add(plButton);

                                    HeroCard plCard = new HeroCard()
                                    {
                                        //Title = document.properties.name[0].value,
                                        Buttons = cardButtons
                                    };

                                    Attachment plAttachment = plCard.ToAttachment();

                                    reply.Attachments.Add(plAttachment);
                                }

                                await turnContext.SendActivityAsync(reply);

                                //var replyToConversation = turnContext.Activity.CreateReply();
                                //replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                                //replyToConversation.Attachments = new List<Attachment>();

                                //Dictionary<string, string> cardContentList = new Dictionary<string, string>();
                                //cardContentList.Add("PigLatin", "https://<ImageUrl1>");
                                //cardContentList.Add("Pork Shoulder", "https://<ImageUrl2>");
                                //cardContentList.Add("Bacon", "https://<ImageUrl3>");

                                ////Put the most recent entries first
                                //foreach (var document in documentsGraphModel)
                                //{


                                //}

                                //foreach (KeyValuePair<string, string> cardContent in cardContentList)
                                //{



                                //    List<CardImage> cardImages = new List<CardImage>();
                                //    cardImages.Add(new CardImage(url: cardContent.Value));

                                //    List<CardAction> cardButtons = new List<CardAction>();

                                //    CardAction plButton = new CardAction()
                                //    {
                                //        Value = $"https://en.wikipedia.org/wiki/{cardContent.Key}",
                                //        Type = "openUrl",
                                //        Title = "WikiPedia Page"
                                //    };

                                //    cardButtons.Add(plButton);

                                //    HeroCard plCard = new HeroCard()
                                //    {
                                //        Title = $"I'm a hero card about {cardContent.Key}",
                                //        Subtitle = $"{cardContent.Key} Wikipedia Page",
                                //        Images = cardImages,
                                //        Buttons = cardButtons
                                //    };

                                //    Attachment plAttachment = plCard.ToAttachment();
                                //    replyToConversation.Attachments.Add(plAttachment);
                                //}

                                //await turnContext.SendActivityAsync(replyToConversation);
                            }
                            else
                            {
                                await turnContext.SendActivityAsync(string.Format("I did not find any documents associated with {0}.", topic));
                            }
                        }
                        break;

                    case GetMattersIntent:
                        await turnContext.SendActivityAsync($"Getting your matters. This may take a moment.\n");

                        var matterGraphModel = GraphAnalysisBusinessLogic.GetMatters(this);
                        if (matterGraphModel.Count > 0)
                        {
                            await turnContext.SendActivityAsync("I found the following matters:");

                            foreach (var matter in matterGraphModel)
                            {
                                await turnContext.SendActivityAsync(matter.properties.name[0].value);
                            }
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("I did not find any matters.");
                        }
                        break;

                    case GetRecentDocumentsIntent:
                        await turnContext.SendActivityAsync($"Getting your recent documents. This may take a moment.\n");

                        break;

                    case GreetingIntent:
                        await turnContext.SendActivityAsync($"Hello, I'm Tagulous, CELA's knowledge management assistant. If you want to know what I can do as a question like \"How can you help me?\"\n");

                        break;

                    case HelpIntent:
                        await turnContext.SendActivityAsync($"You seem to be looking for some help. I am can do some basic things for you.\n");

                        await turnContext.SendActivityAsync($"Specifically, I can do the following, and I provide some examples of how you can ask for that service.\n");

                        await turnContext.SendActivityAsync($"Identifying the person who sends communications with the prescribed tag the most: _Who is our expert on privacy?_\n");

                        await turnContext.SendActivityAsync($"Listing the matters engaged through this system: _Please get my matters._\n");

                        await turnContext.SendActivityAsync($"Listing the documents associated with a tag: _Please get me documents associated with testing._\n");

                        break;

                    case NoneIntent:
                        break;

                    case TagUsersIntent:
                        await turnContext.SendActivityAsync($"Getting recent user activity. This may take a moment.\n");

                        break;

                    case TopTagsIntent:
                        //CommunicationProcessingBL.TransactGraphQuery(client, )
                        //await QueryAzureTableForMostUsedTags(turnContext, recognizerResult);
                        break;

                    case TopicExpert:
                        await FindTopicExpert(turnContext, luisResults);

                        break;

                    default:
                        await turnContext.SendActivityAsync($"==>LUIS Top Scoring Intent: {topIntent.Value.intent}, Score: {topIntent.Value.score}\n");

                        break;
                    }
                }
                else
                {
                    var msg = @"No LUIS intents were found.
                            This sample is about identifying two user intents:
                            'Calendar.Add'
                            'Calendar.Find'
                            Try typing 'Add Event' or 'Show me tomorrow'.";
                    await turnContext.SendActivityAsync(msg);
                }
            }
            else if (activity.Type == ActivityTypes.ConversationUpdate)
            {
                await SendWelcomeMessageAsync(turnContext, cancellationToken);
            }

            await _conversationState.SaveChangesAsync(turnContext);

            await _userState.SaveChangesAsync(turnContext);
        }