2017-07-19 61 views
-1

我需要處理bot框架對話框的錯誤,我有IDialogContext發送消息或調用另一個對話框。 目前,我有殭屍框架對話框錯誤處理

try 
{ 
    await Conversation.SendAsync(); 
} 
catch (Exception e) 
{ 
    HandleExceptions(e, activity); 
} 

在MessagesController,但在這個級別的Microsoft.Bot.Builder.Dialogs.DefaultIfException已經發出錯誤消息發送回用戶。 在DefaultIfException之前以及如何攔截錯誤,將其處理並傳播到DefaultIfException。

+2

的[錯誤以BOT框架對話框處理(可能的複製https://stackoverflow.com/questions/45068972/error-handling-in- BOT框架的對話框) –

回答

0

您可以使用您的異常圖層捕獲bot異常。下面的代碼將幫助您指導進一步進行。我正在使用它,它工作正常。

try 
    { 
     // your code 
    } 
    catch (Exception ex) 
    { 
     await BotException.GenerateBotException(message.From.Name, ex); 
    } 

之後,你需要創建一個Exception類捕捉到日誌中您的自定義數據庫或異常詳細信息發送電子郵件通知。

using System; 
using GPP.Bot.DataAccessLayer; 
using System.Collections.Generic; 
using System.Net.Mail; 
using System.Threading.Tasks; 
using System.Web.Configuration; 
using Microsoft.SharePoint.Client; 
using Microsoft.SharePoint.Client.Utilities; 

namespace Gpp.Bot.ExceptionHandling 
{ 
    public class BotException 
    { 
     public static List<ErrorLogProperties> BOTErrorLog(string Environment, string exceptionStack, string exceptionSource, string fullException, string loggedInUser, string exceptionDateTime) 
     { 
      // this code to capture data in Cutome DB 
      return DbHelper.ExecuteList<ErrorLogProperties>(
       new Command { ComandText = "Your Stored Procedure" }, 
       new Parameter<string, object>("Environment", Environment), 
       new Parameter<string, object>("exceptionStack", exceptionStack), 
       new Parameter<string, object>("exceptionSource", exceptionSource), 
       new Parameter<string, object>("fullException", fullException), 
       new Parameter<string, object>("loggedInUser", loggedInUser), 
       new Parameter<string, object>("exceptionDateTime", exceptionDateTime) 
       ); 

     } 

     public static async Task GenerateBotException(string LLID, Exception ex) 
     { 
      BotExceptionNotification(LLID.Split('*')[1], ex.StackTrace, ex.Source, ex.Message,LLID.Split('*')[0], DateTime.Now.ToString()); 
      BOTErrorLog(LLID.Split('*')[1], ex.StackTrace, ex.Source, ex.Message,LLID.Split('*')[0], DateTime.Now.ToString()); 
     } 

     public static void BotExceptionNotification(string Environment, string exceptionStack, string exceptionSource, 
      string fullException, string loggedInUser, string exceptionDateTime) 
     { 
      // Send email code goes here using above peramaeters in you html 
     } 

    } 
} 

不要讓我知道如果你需要更多的幫助