2017-12-18 107 views
1

在QnA Maker API中,當找不到結果時,它會返回一些默認消息,或者我們可以更改該消息,但是我想運行一個函數/方法當沒有結果來源。以下是代碼。Azure Bot Framework,QnA Maker API,如何在QnA對話中獲取查詢文本

public QnaDialog(): base(
     new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnaSubscriptionKey"], 
     ConfigurationManager.AppSettings["QnaKnowledgebaseId"], "Hmm, I wasn't able to find any relevant content. Can you try asking in a different way? or try with typing help.", 0.5))) 
    { 
     //this is what i want to call, this is working but **i am not able to get query text here** 
     SendEmail email = new SendEmail(); 
     email.SendEmailtoAdmin("Query_Text", "Email ID"); 
    } 

回答

3

,看一下在GitHub上QnaMakerDialog實施here

你會看到你有幾個選項,更容易的是覆蓋在Qna搜索之後調用的DefaultWaitNextMessageAsync方法。

protected virtual async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result) 
    { 
     if (result.Answers.Count == 0) 
     { 
      // Here you have the query text in message.Text so: 
      SendEmail email = new SendEmail(); 
      email.SendEmailtoAdmin(message.Text, "Email ID"); 
     } 

     context.Done(true); 
    } 

請注意,如果你想避免派出約沒有QNA發現的消息,你應該重寫MessageReceivedAsync替代和改變塊中的代碼if (sendDefaultMessageAndWait)

相關問題