コード例 #1
0
        //Creates the necessary objects and sends the request to the service class to update the knowledgebase with the userQuestion
        protected async Task StoreFeedback(IDialogContext context)
        {
            if (this.feedbackRecord != null)
            {
                // Uncomment to check for more than 1 keyword before adding question to phrase
                //var kWords = await Global.TextAnalytics.GetKeyphrases(feedbackRecord.userQuestion);
                //if (kWords.documents[0].keyPhrases.Length >= 2) // if the query contains more than one keyword update the knowledge base with query
                //{
                var kbUpdates = new KbUpdateRequest {
                    update = new ItemsToUpdate {
                        QnaList = new List <KbItemToUpdate>()
                    }
                };
                var questionToUpdate = new KbItemToUpdate()
                {
                    qnaId = this.feedbackRecord.kbQuestionId, questions = new QuestionsUpdateModel {
                        add = new string[] { this.feedbackRecord.userQuestion }
                    }
                };
                kbUpdates.update.QnaList.Add(questionToUpdate);
                await qnaService.UpdateKnowledgebase(kbUpdates);

                //}
            }
        }
コード例 #2
0
        public async Task UpdateKnowledgebase(KbUpdateRequest requestObject)
        {
            string responseString;
            var    qnamakerBaseUri     = this.BaseUri;
            var    knowledgebaseId     = this.KnowledgeBaseId; // Use knowledge base id created.
            var    qnamakerEndpointKey = this.EndpointKey;     //Use endpoint key assigned to you.

            //Build the URI
            var updateBaseEndpoint = "https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/";
            var qnamakerUriBase    = new Uri(qnamakerBaseUri);
            var builder            = new UriBuilder($"{updateBaseEndpoint}/knowledgebases/{knowledgebaseId}");

            var postBody = JsonConvert.SerializeObject(requestObject);



            //Send the POST request
            using (WebClient client = new WebClient())
            {
                //Set the encoding to UTF8
                client.Encoding = System.Text.Encoding.UTF8;
                //Add the subscription key header
                client.Headers.Add("Ocp-Apim-Subscription-Key", $"{this.SubscriptionKey}");
                client.Headers.Add("Content-Type", "application/json");
                try
                {
                    responseString = client.UploadString(builder.Uri, "PATCH", postBody);
                }
                catch (WebException err)
                {
                    throw new Exception(err.Message);
                }
            }
        }