備註
Copilot Studio 機器人已重新命名為 Copilot 代理程式 (代理程式或 AI 代理程式)。 真人專員現已重新命名為客戶服務代表 (服務代表或代表)。 在我們更新產品 UI、文件和訓練內容時,您可能會發現我們不時提及舊的和新的詞彙。
對於 Azure 代理,你必須安裝代理 SDK 並實例化 Omnichannel 中介軟體,才能設定代理情境。
在您的專案中安裝機器人 SDK
若要開啟 NuGet 套件管理員,請以滑鼠右鍵按一下您的專案,然後選取 [管理 NuGet 套件]。
在 NuGet 套件管理器中,選擇套件來源為 nuget.org ,並瀏覽「Microsoft.Dynamics.AgentsSDK.Middleware」。 選擇套件,然後選擇 安裝。 欲了解更多,請參閱 Nuget頁面。
或者,您可以在 NuGet CLI 中使用下列命令。
Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
代理 SDK 已安裝,且全通路中介軟體已在你的專案中可用。
在你的代理程式碼中使用全通路中介軟體
開啟 AdapterWithErrorHandler.cs 檔案。
新增匯入語句並實例化全通路中介軟體。
using Microsoft.Dynamics.AgentsSDK.Middleware.Core; Use(new OmnichannelMiddleware());using System.Globalization; using System.Text; using Microsoft.Agents.Connector; using Microsoft.Agents.Core; using Microsoft.Agents.Core.Errors; using Microsoft.Extensions.Logging; using Microsoft.Dynamics.AgentsSDK.Middleware.Core; namespace Microsoft.CCaaS.MessagingRuntime.TestAgent; public class AdapterWithErrorHandler : CloudAdapter { public AdapterWithErrorHandler( IChannelServiceClientFactory channelServiceClientFactory, IActivityTaskQueue activityTaskQueue, ILogger<CloudAdapter> logger) : base(channelServiceClientFactory, activityTaskQueue, logger) { // OmnichannelMiddleware has special handling for OC event messages Use(new OmnichannelMiddleware()); OnTurnError = async (turnContext, exception) => { var exceptionInfo = GetExceptionInfo(exception); logger.LogAppException(exceptionInfo, exception); // Send a message to the user await turnContext.SendActivityAsync($"The bot encountered an error or bug.{Environment.NewLine}{exceptionInfo}"); await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); // Send a trace activity, which will be displayed in the Bot Framework Emulator await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError"); }; } private static string GetExceptionInfo(Exception exception) { var sb = new StringBuilder(); // Pull some well known info from ErrorResponse.Exception if available. if (exception is ErrorResponseException responseException) { sb.AppendLine(CultureInfo.InvariantCulture, $"Error code: {responseException.Body?.Error?.Code ?? "NA"}"); sb.AppendLine(CultureInfo.InvariantCulture, $"Error message: {responseException.Body?.Error?.Message ?? "NA"}"); } sb.AppendLine(CultureInfo.InvariantCulture, $"Exception message: {exception.Message}"); sb.AppendLine(); sb.AppendLine(exception.ToString()); var exceptionInfo = sb.ToString(); return exceptionInfo; } }