public PartialViewResult ResultCardPartial(string kbId, string answer, string question, string id)
        {
            List <DeserializedAnswer> answers = JsonConvert.DeserializeObject <List <DeserializedAnswer> >(answer);

            SelectedSearchResult selectedSearchResult = new SelectedSearchResult()
            {
                KBId              = kbId,
                Question          = question,
                Answers           = answers,
                ListItemId        = id,
                SharePointListUrl = this.Session["SharePointUrl"].ToString(),
            };

            return(this.PartialView(selectedSearchResult));
        }
Exemple #2
0
        public PartialViewResult ResultCardPartial(string kbId, string answer, string question, string id)
        {
            List <DeserializedAnswer> answers = JsonConvert.DeserializeObject <List <DeserializedAnswer> >(answer);

            SelectedSearchResult selectedSearchResult = new SelectedSearchResult()
            {
                KBId              = kbId,
                Question          = question,
                Answers           = answers,
                ListItemId        = id,
                SharePointListUrl = this.Session["SharePointUrl"] != null? this.Session["SharePointUrl"].ToString():"https://m365x067565.sharepoint.com/_layouts/15/sharepoint.aspx",
            };

            return(this.PartialView(selectedSearchResult));
        }
        // Handle incoming invoke activities
        private HttpResponseMessage HandleInvokeActivity(Activity activity)
        {
            if (activity.Name == "composeExtension/fetchTask")
            {
                string user      = activity.From.Id;
                string tenant    = activity.GetTenantId();
                string jwt       = this.jwtHelper.GenerateToken(activity.From.Id, activity.From.Properties["aadObjectId"].ToString(), activity.GetTenantId(), this.jwtLifetimeInMinutes);
                string sessionId = Guid.NewGuid().ToString();

                TaskInfo taskInfo = new TaskInfo()
                {
                    Url    = $"https://{this.appBaseDomain}/search?token={jwt}&sessionId={sessionId}&theme={{theme}}",
                    Title  = Strings.MessagingExtensionTitle,
                    Width  = WidthInPixels,
                    Height = HeightInPixels,
                };
                TaskSubmitResponse taskEnvelope = new TaskSubmitResponse()
                {
                    Task = new TaskContinueResult(taskInfo),
                };

                // Log invocation of messaging extension
                this.logProvider.LogEvent("SearchSessionStarted", new Dictionary <string, string>
                {
                    { "SessionId", sessionId },
                });

                return(this.Request.CreateResponse(HttpStatusCode.OK, taskEnvelope));
            }
            else if (activity.Name == "composeExtension/submitAction")
            {
                var jsonSerializerSettings = new JsonSerializerSettings()
                {
                    ContractResolver = new CamelCaseExceptDictionaryKeysResolver(),
                    Formatting       = Formatting.None,
                };
                var reply = ((JObject)activity.Value)["data"].ToString();
                SelectedSearchResult selectedSearchResult = JsonConvert.DeserializeObject <SelectedSearchResult>(reply, jsonSerializerSettings);

                List <AdaptiveFact> facts = new List <AdaptiveFact>();
                foreach (DeserializedAnswer child in selectedSearchResult.Answers)
                {
                    facts.Add(new AdaptiveFact()
                    {
                        Title = Convert.ToString(child.Question + ":"),
                        Value = Convert.ToString(child.Answer),
                    });
                }

                AdaptiveCard card = new AdaptiveCard(AdaptiveCardVersion)
                {
                    Body = new List <AdaptiveElement>()
                    {
                        new AdaptiveContainer()
                        {
                            Items = new List <AdaptiveElement>()
                            {
                                new AdaptiveTextBlock()
                                {
                                    Text   = selectedSearchResult.Question,
                                    Weight = AdaptiveTextWeight.Bolder,
                                    Wrap   = true,
                                    Size   = AdaptiveTextSize.Large,
                                },
                            },
                        },
                        new AdaptiveContainer()
                        {
                            Items = new List <AdaptiveElement>()
                            {
                                new AdaptiveFactSet()
                                {
                                    Facts = facts ?? new List <AdaptiveFact>(),
                                },
                            },
                        },
                    },
                    Actions = new List <AdaptiveAction>()
                    {
                        new AdaptiveOpenUrlAction()
                        {
                            Url   = new Uri(this.CreateListItemUrl(selectedSearchResult.SharePointListUrl, selectedSearchResult.ListItemId)),
                            Title = Strings.ResultCardButtonTitle,
                        },
                    },
                };

                var result = new Attachment()
                {
                    Content     = card,
                    ContentType = AdaptiveCard.ContentType,
                };
                var preview = new ThumbnailCard
                {
                    Title = selectedSearchResult.Question,
                };

                ComposeExtensionResponse composeExtensionResponse = new ComposeExtensionResponse()
                {
                    ComposeExtension = new ComposeExtensionResult()
                    {
                        Attachments = new List <ComposeExtensionAttachment>()
                        {
                            result.ToComposeExtensionAttachment(preview.ToAttachment())
                        },
                        Type             = ComposeExtensionResultType.Result,
                        AttachmentLayout = AttachmentLayoutTypes.List,
                    },
                };

                // Log that the search result was selected and turned into a card
                this.logProvider.LogEvent("SearchResultShared", new Dictionary <string, string>
                {
                    { "KnowledgeBaseId", selectedSearchResult.KBId },
                    { "ListItemId", selectedSearchResult.ListItemId },
                    { "SessionId", selectedSearchResult.SessionId },
                });

                return(this.Request.CreateResponse(HttpStatusCode.OK, composeExtensionResponse));
            }

            return(new HttpResponseMessage(HttpStatusCode.Accepted));
        }