2017-05-31 7 views
0

QnA Makerを使用してボットを作成し、FBページとMicrosoft Bot Frameworkに接続されたFB Appをセットアップしました。しかし、何かが欠けている。 Microsoft QnAメーカーをBotフレームワークに接続するにはどうすればいいですか? (FWIW - 目標は、非営利目的のイベントに関するFAQに答えるFB Messengerボットです)。ありがとうMicrosoft QnA Makerをボットフレームワークに接続

+0

BotフレームワークではなくMS Azureを使用することをお勧めします。シンプル! –

答えて

0

あなたはQNAメーカーに登録し、以下のコードを使用して回答を得ることができます。ボットフレームワークに登録する必要はありません。

サンプルリクエスト

string responseString = string.Empty; 

var query = “hi”; //User Query 
var knowledgebaseId = “YOUR_KNOWLEDGE_BASE_ID”; // Use knowledge base id created. 
var qnamakerSubscriptionKey = “YOUR_SUBSCRIPTION_KEY”; //Use subscription key assigned to you. 

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

//Add the question as part of the body 
var postBody = $"{{\"question\": \"{query}\"}}"; 

//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", qnamakerSubscriptionKey); 
    client.Headers.Add("Content-Type", "application/json"); 
    responseString = client.UploadString(builder.Uri, postBody); 
} 

サンプル応答

using Newtonsoft.Json; 

private class QnAMakerResult 
{ 
    /// <summary> 
    /// The top answer found in the QnA Service. 
    /// </summary> 
    [JsonProperty(PropertyName = "answer")] 
    public string Answer { get; set; } 

    /// <summary> 
    /// The score in range [0, 100] corresponding to the top answer found in the QnA Service. 
    /// </summary> 
    [JsonProperty(PropertyName = "score")] 
    public double Score { get; set; } 
} 
//De-serialize the response 
QnAMakerResult response; 
try 
{ 
    response = JsonConvert.DeserializeObject<QnAMakerResult>(responseString); 
} 
catch 
{ 
    throw new Exception("Unable to deserialize QnA Maker response string."); 
} 

注:サービス

にログインし、作成するために必要な知識ベースのIDとサブスクリプションキーを取得しますあなたが私に知らせる任意のヘルプ

関連する問題