Note
Copilot Studio ボットは、Copilot エージェント (エージェントまたは AI エージェント) として名前が変更されます。 ヒューマン エージェントの名前が customer service 担当者 (サービス担当者または担当者) に変更されました。 製品の UI、ドキュメント、トレーニング コンテンツを更新しているときに、古い用語と新しい用語への言及に出くわす可能性があります。
Azure エージェントの場合は、エージェント コンテキストを構成する前に、エージェント SDK をインストールし、オムニチャネル ミドルウェアをインスタンス化する必要があります。
プロジェクトにボット SDK をインストールする
NuGet パッケージ マネージャーを開くには、プロジェクトを右クリックし、[ NuGet パッケージの管理] を選択します。
NuGet パッケージ マネージャーで、パッケージ ソースを nuget.org として選択し、"Microsoft.Dynamics.AgentsSDK.Middleware" を検索します。 パッケージを選択し、インストールを選択します。 詳細については、 Nuget のページを参照してください。
または、NuGet CLI で次のコマンドを使用することもできます。
Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
エージェント SDK がインストールされ、オムニチャネル ミドルウェアがプロジェクトで使用できるようになりました。
エージェント コードでオムニチャネル ミドルウェアを使用する
AdapterWithErrorHandler.cs ファイルを開きます。
import ステートメントを追加し、オムニチャネル ミドルウェアをインスタンス化します。
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; } }
次のステップ
アクティビティ JSON を解析してエージェント コンテキストを取得する