Note
本文說明由標準執行架構提供的 Agent 或 Agent 流程中所使用的功能。
將 ServiceNow Virtual Agent 連線至 Copilot Studio Agent,並在 ServiceNow 中設定轉接給真人專員。 該整合使用 Azure 函式來中繼 Direct Line 活動,並使用自訂的 ServiceNow 轉換器來偵測交接事件。
Note
如需詳細資訊,請參閱「設定轉接至任何一般互動中樞」。 Copilot Studio 提供整合人類客服解決方案(如 ServiceNow)的介接點;你的開發團隊負責實作整合。
以下步驟僅為建議,您需要一個軟體開發團隊來執行它們。 此程序適合具備豐富開發工具、工具及整合開發環境(IDE)知識的資深 IT 專業人士、開發者或系統整合商。
概觀
Copilot Studio 與 ServiceNow 之間的整合需要下列高階設定步驟:
部署一個 Azure 函式作為 Direct Line 的中繼。
在 ServiceNow 中設定機器人互連。
對應 ServiceNow Virtual Agent 與 Copilot Studio 之間的主題。
擴充
DirectLinePrimaryBotIntegrationInboundTransformer。在 Copilot Studio 中設定交接。
Prerequisites
開始之前,請確定您具備下列先決條件:
- 一個啟用 ServiceNow Virtual Agent 和 ServiceNow Bot Interconnect 的活躍 ServiceNow 帳號。 你需要 ServiceNow Yokohama 或更新版本。
- 一個設定為無認證的 Copilot Studio 代理程式。 此設定適用於終端使用者登入;伺服器間中繼使用 Direct Line 秘密授權通道存取。
- ServiceNow 的系統管理員存取權。
建立 Azure Function 作為 Direct Line 的轉送器
Azure Functions 作為中繼,讓 ServiceNow Bot Interconnect 能從與 Copilot Studio agent 進行的持續對話中擷取活動,例如訊息和事件。
Important
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"
}
建立並部署函式
你可以建立並部署 ServiceNow 文件中描述的 v3 Azure 函式,或是 Copilot Studio GitHub 倉庫中可用的 v4 Azure 函式。
選項 1:部署 v3 Azure 函式
若要建立及部署 v3 Azure 函式,請遵循 ServiceNow 檔中所述的步驟:
將函式部署至 Azure,並擷取函式 URL 以用於 ServiceNow Bot 互連。
選項 2:部署 v4 Azure 函式
或者,您可以使用 Copilot Studio GitHub 存放庫中提供的 v4 Azure 函式:
複製 Copilot Studio Samples 存放庫。 在 Visual Studio Code 中開啟該
contact-center/servicenow/DirectLineAzureFunction專案。請依照專案的設置說明操作。 在 Azure 建立一個函式應用程式,並部署提供的中繼專案。 不要將轉送取代為範本產生的新 HTTP 函數。 更多資訊請參閱 部署專案檔案。
部署後,複製中繼 HTTP 函式的 URL 用於 ServiceNow 機器人互連。 使用函式端點,而非函式應用程式的基礎網址。 想了解更多,請參考 在 Azure 中取得 HTTP 觸發函式的 URL。
在 ServiceNow 中設定 Bot 互連
在 ServiceNow 虛擬代理程式與 Copilot Studio 之間進行主題映射
- 建立一個 Virtual Agent Bot Interconnect Shell 主題,以呼叫 Copilot Studio 主題。
擴充 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;
}
建立自訂轉換器
在 ServiceNow 中,切換至 Bot 互連 應用程式範圍。
選擇右上角的地球圖示。
從應用程式清單中選取 [Bot 互連 ]。
建立新的 Include 指令碼。
前往「系統定義>Script Includes」。
選擇 新建。
設定下列設定:
-
姓名:
CustomDirectLineInboundTransformer -
API 名稱:
sn_va_bot_ic.CustomDirectLineInboundTransformer(自動產生) - 應用程式:Bot 互聯(自動選擇)
- 可存取來源:此應用程式範圍僅限
- 作用中:已選取
將預設文稿內容取代為 Copilot Studio 範例存放庫中的自定義轉換器程序代碼。
點選 提交 以儲存 腳本內嵌。
更新 Bot 互連設定
去 Workflow Studio。
在 ServiceNow 裡,進入 Workflow Studio。
在 「動作」中,找到 Direct Line主要機器人整合入站轉換器。
改變變壓器的動作。
開啟 Direct Line Primary Bot 整合輸入轉換器 動作。
在指令碼編輯器中,註解化預設轉換器註解,並將其取代為對自訂轉換器的呼叫。
(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);儲存操作的變更並發佈。
設定轉接
若要在 ServiceNow 中設定轉接給真人專員,請新增「轉接交談」節點,並放在 Agent 的「升級」主題中。
在 Copilot Studio 中,開啟您的 Agent,然後移至主題>系統>上呈。
選取 + [新增節點] >主題管理>[傳輸交談]。
儲存您的主題並發布您的代理。
傳輸對話節點會handoff.initiate傳送一個事件,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
Troubleshooting
如果您在 ServiceNow 虛擬代理程式聊天小工具中遇到錯誤,請遵循下列疑難解答步驟:
檢查 Azure 函式記錄
確認你的 Azure 函式是否正常運作,沒有回傳錯誤。
透過 Azure Functions 串流日誌查看即時日誌。
請檢查 Application Insights 以取得詳細的遙測和錯誤資訊。
開啟 ServiceNow 除錯
使用 ServiceNow 的內建偵錯工具來追蹤執行流程:
在 ServiceNow 開啟 腳本追蹤。
重複造成錯誤的動作。
檢視追蹤日誌以找出問題發生的位置。
監視 Copilot Studio 引動過程
請確保您的 Copilot Studio 代理被正確呼叫:
監視遙測,以確認代理程式正在接收來自 ServiceNow 的要求。
檢查代理程式執行中是否有任何錯誤或非預期的行為。
常見問題與解決方案
- 交接未觸發:確認自訂轉換器是否啟用,且轉移對話節點是否正確設定。
- 驗證錯誤:請確定已在 ServiceNow 中正確設定 Direct Line 秘密。 具體來說,要把 ServiceNow 裡的憑證紀錄和連線紀錄連結起來。
- 函式逾時:檢查 Azure 函式是否逾時,必要時提高逾時設定。