共用方式為


轉接給 ServiceNow

此文件提供有關如何建立 ServiceNow 虛擬助理並將其連接至 Copilot Studio Agent,以及如何上呈至 ServiceNow 真人專員的逐步指示。 這項整合可讓您使用平臺和產生式答案的功能來增強代理程序體驗。

注意

有關更多詳細資訊,請參閱設定移交給任何通用參與中心。 Copilot Studio 僅提供鉤點,讓您整合人類專員解決方案,例如 ServiceNow。

以下步驟僅為建議,您需要一個軟體開發團隊來執行它們。 此程式適用於經驗豐富的 IT 專業人員、開發人員或系統整合者,他們對於開發人員工具、公用程式和整合開發環境 (IDE) 有紮實的瞭解。

概觀

Copilot Studio 與 ServiceNow 之間的整合需要下列高階設定步驟:

  1. 建立 Azure 函式作為 DirectLine 的中繼。

  2. 在 ServiceNow 中設定機器人互連。

  3. 在 ServiceNow Virtual Agent 與 Copilot Studio 之間對應主題。

  4. 擴充 DirectLinePrimaryBotIntegrationInboundTransformer。

  5. 在 Copilot Studio 中設定交接。

必要條件

在開始之前,請確定您符合下列先決條件:

  • 啟用 ServiceNow 虛擬 Agent 且已啟用 ServiceNow 機器人互連的使用中 ServiceNow 帳戶。 (需要 ServiceNow Yokohama 版或更高版本)。
  • 已設定 no authentication 的 Copilot Studio Agent (此模式將伺服器對伺服器驗證與 Direct Line 祕密搭配使用)。
  • ServiceNow 的系統管理員存取權。

建立 Azure 函式做為 DirectLine 的中繼站

此 Azure 函式發揮轉送作用,讓 ServiceNow 機器人互連服務可以從正在與 Copilot Studio Agent 進行的交談中擷取活動 (例如訊息和事件)。

這很重要

Azure 函式的預設等候時間為 2,000 毫秒(2 秒),在 Copilot Studio 中使用產生協調流程時可能太短。 如果 ServiceNow 中的虛擬代理程式未收到訊息,請考慮增加等候時間。

ServiceNow Bot 互連傳送的範例要求

GET /api/relayToDirectLine HTTP/1.1
Host: your-function-app.azurewebsites.net
Authorization: Bearer YOUR_DIRECT_LINE_SECRET_HERE
ConversationId: abc123def456-conversation-id
Watermark: 5
WaitTime: 3000

來自 Azure 函式的範例回應

{
    "activities": [
        {
            "type": "message",
            "id": "0000001",
            "timestamp": "2025-07-13T13:46:43.6095506Z",
            "text": "Hello, I'm a Copilot Studio Agent.",
            "from": {
                "id": "bot-id",
                "name": "Copilot Studio Agent",
                "role": "bot"
            },
            "conversation": {
                "id": "wwjmISGzmd3FzMEAgotiJ-us"
            }
        },
        {
            "type": "message",
            "id": "0000002",
            "timestamp": "2025-07-13T13:46:45.0000000Z",
            "text": "speak to a live agent",
            "from": {
                "id": "user-id",
                "name": "User",
                "role": "user"
            },
            "conversation": {
                "id": "wwjmISGzmd3FzMEAgotiJ-us"
            }
        },
        {
            "type": "event",
            "id": "0000006",
            "timestamp": "2025-07-13T13:46:51.2854808Z",
            "name": "handoff.initiate",
            "value": {
                "va_LastPhrase": "speak to a live agent",
                "va_Topics": ["Escalate"]
            }
        }
    ],
    "watermark": "10"
}

建立和部署函式

您可以選擇建立和部署 v3 Azure 函式,如 ServiceNow 檔中所述,或 Copilot Studio GitHub 存放庫中提供的 v4 Azure 函式。

選項 1:部署 v3 Azure 函式

若要建立及部署 v3 Azure 函式,請遵循 ServiceNow 檔中所述的步驟:

  1. 使用 Visual Studio Code 在 Microsoft Azure 中建立 JavaScript 函數

  2. 將函式部署至 Azure,並擷取函式 URL 以用於 ServiceNow Bot 互連。

選項 2:部署 v4 Azure 函式

或者,您可以使用 Copilot Studio GitHub 存放庫中提供的 v4 Azure 函式:

  1. Copilot Studio 範例複製存放庫。 函式位於 底下 CopilotStudioSamples/IntegrateWithEngagementHub/ServiceNow/DirectLineAzureFunction

  2. 遵循 使用 Visual Studio Code 在 Azure 中建立 JavaScript 函式中的指示。

  3. 在函式應用程式的 [ 概觀 ] 頁面上,複製函式URL。

在 ServiceNow 中設定 Bot 互連

  1. 取得 Agent 的 Direct Line 祕密

  2. 將 Direct Line 祕密金鑰新增至虛擬 Agent 機器人互連執行個體

在 ServiceNow 虛擬代理程式與 Copilot Studio 之間進行主題映射

  1. 若要呼叫 Copilot Studio 主題,請建立虛擬 Agent 機器人互連殼層主題

擴充 DirectLinePrimaryBotIntegrationInboundTransformer

需要將交談移交給真人專員時,內建 DirectLinePrimaryBotIntegrationInboundTransformer 不會剖析 Copilot Studio handoff.initiate 事件。

shouldConnectToAgent 中的 DirectLinePrimaryBotIntegrationInboundTransformer 函式一律會傳回 false:

shouldConnectToAgent: function(response) {
    return false;
}

若要正確處理交接事件,請建立自定義轉換器,以擴充預設轉換器並偵測 handoff.initiate 事件。

shouldConnectToAgent: function() {
        var response = this._response || {};
        var activities = response.activities || [];

        var handoffDetected = activities.some(function(activity) {
            return activity.type === "event" && activity.name === "handoff.initiate";
        });

        if (handoffDetected) {
            return true;
        }
        return false;
    }

建立自訂轉換器

  1. 在 ServiceNow 中,切換至 Bot 互連 應用程式範圍。

    1. 選取右上角的地球圖示。

    2. 從應用程式清單中選取 [Bot 互連 ]。

  2. 建立新的 Include 指令碼。

    1. 瀏覽至系統定義>Include 指令碼

    2. 選擇 新建

    3. 設定下列設定:

    • 名稱CustomDirectLineInboundTransformer
    • API 名稱sn_va_bot_ic.CustomDirectLineInboundTransformer (自動產生)
    • 應用程式:Bot 互聯(自動選擇)
    • 可存取來源:此應用程式範圍僅限
    • 作用中: ✓ (已核取)
  3. 將預設文稿內容取代為 Copilot Studio 範例存放庫中的自定義轉換器程序代碼。

  4. 若要儲存 腳本包含,請選取 提交

更新 Bot 互連設定

  1. 流覽至 Workflow Studio

    1. 在 ServiceNow 中,流覽至 Workflow Studio

    2. [動作] 底下,找出 Direct Line 主要 Bot 整合輸入轉換器

  2. 修改轉換器動作。

    1. 開啟 Direct Line Primary Bot 整合輸入轉換器 動作。

    2. 在指令碼編輯器中,註解化預設轉換器註解,並將其取代為對自訂轉換器的呼叫。

    (function execute(inputs, outputs) {
       var clientVariables = JSON.parse(inputs['client_variables']);
       var response = JSON.parse(inputs['response']);
       //set client variables
       response.clientVariables = clientVariables;
    
       //var transformedResponse = new sn_va_bot_ic.DirectLinePrimaryBotIntegrationInboundTransformer(response).transformResponse();
       var transformedResponse = new sn_va_bot_ic.CustomDirectLineInboundTransformer(response).transformResponse();
    
       outputs['transformed_response'] = transformedResponse;
     })(inputs, outputs);
    
  3. 儲存操作的變更並發佈。

設定轉接

若要啟用 ServiceNow 真人專員轉接,請將轉移交談節點新增至 Agent 的上呈主題。

  1. 在 Copilot Studio 中,開啟您的代理程式,然後瀏覽至 議題>系統>升級

  2. 選取 + [新增節點] >主題管理>[傳輸交談]。

  3. 儲存您的主題並發布您的代理。

轉接對話節點會發出一個事件,由 ServiceNow 自定義轉換器偵測和處理。

範例上呈主題 YAML

您也可以匯入下列 YAML 設定,以取得包含轉移功能的完整上呈主題:

kind: AdaptiveDialog
startBehavior: CancelOtherTopics
beginDialog:
  kind: OnEscalate
  id: main
  intent:
    displayName: Escalate
    includeInOnSelectIntent: false
    triggerQueries:
      - Talk to agent
      - Talk to a person
      - Talk to someone
      - Call back
      - Call customer service
      - Call me please
      - Call support
      - Call technical support
      - Can an agent call me
      - Can I call
      - Can I get in touch with someone else
      - Can I get real agent support
      - Can I get transferred to a person to call
      - Can I have a call in number Or can I be called
      - Can I have a representative call me
      - Can I schedule a call
      - Can I speak to a representative
      - Can I talk to a human
      - Can I talk to a human assistant
      - Can someone call me
      - Chat with a human
      - Chat with a representative
      - Chat with agent
      - Chat with someone please
      - Connect me to a live agent
      - Connect me to a person
      - Could some one contact me by phone
      - Customer agent
      - Customer representative
      - Customer service
      - I need a manager to contact me
      - I need customer service
      - I need help from a person
      - I need to speak with a live agent
      - I need to talk to a specialist please
      - I want to talk to customer service
      - I want to proceed with live support
      - I want to speak with a consultant
      - I want to speak with a live tech
      - I would like to speak with an associate
      - I would like to talk to a technician
      - Talk with tech support member

  actions:
    - kind: TransferConversationV2
      id: transferConversationV2_3JXrI7
      transferType:
        kind: TransferToAgent
        messageToAgent:
        context:
          kind: AutomaticTransferContext

故障排除

如果您在 ServiceNow 虛擬代理程式聊天小工具中遇到錯誤,請遵循下列疑難解答步驟:

檢查 Azure 函式記錄

  1. 確認您的 Azure 函式正常運作,且未傳回錯誤。

  2. 使用 Azure Functions 串流記錄檢視實時記錄。

  3. 請檢查 Application Insights 以取得詳細的遙測和錯誤資訊。

啟用 ServiceNow 偵錯

使用 ServiceNow 的內建偵錯工具來追蹤執行流程:

  1. 在 ServiceNow 中啟用 腳本追蹤

  2. 重複造成錯誤的動作。

  3. 檢閱追蹤記錄,以識別問題發生的位置。

監視 Copilot Studio 引動過程

請確定您的 Copilot Studio 代理程式已正確叫用:

  1. 將 Copilot Studio 代理程式連線到 Application Insights

  2. 監視遙測,以確認代理程式正在接收來自 ServiceNow 的要求。

  3. 檢查代理程式執行中是否有任何錯誤或非預期的行為。

常見問題和解決方案

  • 交接未觸發:確認自定義轉換器處於啟用狀態,且轉移交談節點已正確配置
  • 驗證錯誤:請確定已在 ServiceNow 中正確設定 Direct Line 秘密。 具體而言,ServiceNow 中的認證記錄必須與連線記錄連結。
  • 函式逾時:檢查 Azure 函式是否逾時,必要時調整逾時設定。