虛擬服務專員 Assist

本使用指南會逐步引導您直接呼叫 API,啟用 Virtual Agent Assist 功能。Agent Assist 小幫手會追蹤對話,並使用 Dialogflow 虛擬服務專員為真人服務專員提供工作流程支援,以及偵測意圖以進行資料分析。

您也可以使用 Agent Assist 主控台訓練模型,並使用模擬工具測試模型效能。如需操作說明,請參閱Agent Assist 虛擬助理控制台教學課程

事前準備

如要啟用 Virtual Agent Assist,您必須先導入一或多項 Agent Assist 功能,才能搭配虛擬代理使用。智慧回覆、常見問題、Agent Assist、文章建議和智慧撰寫功能可單獨使用,也可與虛擬服務專員 Agent Assist 搭配使用,或以任何組合形式使用。如需實作詳細資料,請點選下列連結前往相關說明文件。

建立對話

當使用者與真人或虛擬代理開始對話時,您會建立對話如要查看建議,您也必須建立使用者參與者和服務專員參與者,並將他們加入對話。以下各節將逐步說明這個程序。

首先,您必須建立對話:

REST

如要建立對話,請呼叫 Conversation 資源的 create 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的雲端專案 ID
  • LOCATION_ID:您的地區 ID
  • CONVERSATION_PROFILE_ID:建立對話設定檔時收到的 ID

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations

JSON 要求主體:

{
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "IN_PROGRESS",
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z"
}

conversations 後方的路徑區段包含了您的新對話 ID。

Python

如要向 Agent Assist 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

def create_conversation(project_id, conversation_profile_id):
    """Creates a conversation with given values

    Args:
        project_id:  The GCP project linked with the conversation.
        conversation_profile_id: The conversation profile id used to create
        conversation."""

    client = dialogflow.ConversationsClient()
    conversation_profile_client = dialogflow.ConversationProfilesClient()
    project_path = client.common_project_path(project_id)
    conversation_profile_path = conversation_profile_client.conversation_profile_path(
        project_id, conversation_profile_id
    )
    conversation = {"conversation_profile": conversation_profile_path}
    response = client.create_conversation(
        parent=project_path, conversation=conversation
    )

    print("Life Cycle State: {}".format(response.lifecycle_state))
    print("Conversation Profile Name: {}".format(response.conversation_profile))
    print("Name: {}".format(response.name))
    return response

建立使用者參與者

您必須在對話中加入使用者和真人服務專員,才能查看建議。首先,將使用者參與者新增至對話:

REST

如要建立使用者參與者,請在 Participant 資源上呼叫 create 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的雲端專案 ID
  • LOCATION_ID:您的地區 ID
  • CONVERSATION_ID:您的對話 ID

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

JSON 要求主體:

{
  "role": "END_USER",
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "END_USER"
}

participants 後方的路徑區段包含新的使用者參與者 ID。

Python

如要向 Agent Assist 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

建立真人服務專員參與者

在對話中新增真人服務專員參與者:

REST

如要建立真人服務專員參與者,請呼叫 Participant 資源的 create 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的雲端專案 ID
  • LOCATION_ID:您的地區 ID
  • CONVERSATION_ID:您的對話 ID

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

JSON 要求主體:

{
  "role": "HUMAN_AGENT",
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "HUMAN_AGENT"
}

participants 後方的路徑區段包含新的人工服務專員參與者 ID。

Python

如要向 Agent Assist 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

新增使用者的訊息並取得建議

如要為對話新增及分析使用者訊息,請在 Participant 資源上呼叫 analyzeContent 方法。回應會包含 dialogflowAssistAnswers 欄位,內含下列資料:

  • fulfillmentText:包含建議的回覆。您可以設定系統,向真人服務專員顯示這項建議。
  • answer record:建議的專屬 ID。

選取建議

人工服務專員收到建議後,可以接受建議或先編輯再轉給使用者。如要選取建議,請使用真人客服參與者再次撥打電話 analyzeContent。將 suggestionInput 欄位設為所選設定,並提供您先前收到的 answer recordtext override 欄位應包含傳送給使用者的實際文字。以下是設定 suggestionInput 欄位的範例:

{
  "answerRecord": "answer-record",
  "textOverride": {
    "text" : "Yes, there will be ponies.",
    "languageCode": "en-US"
  }
}

完成對話

對話結束後,請使用 API 完成對話。

REST

如要完成對話,請呼叫 conversations 資源的 complete 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的 GCP 專案 ID
  • CONVERSATION_ID:建立對話時收到的 ID

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID:complete

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "COMPLETED",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z",
  "endTime": "2018-11-06T03:50:26.930Z"
}

Python

如要向 Agent Assist 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

def complete_conversation(project_id, conversation_id):
    """Completes the specified conversation. Finished conversations are purged from the database after 30 days.

    Args:
        project_id: The GCP project linked with the conversation.
        conversation_id: Id of the conversation."""

    client = dialogflow.ConversationsClient()
    conversation_path = client.conversation_path(project_id, conversation_id)
    conversation = client.complete_conversation(name=conversation_path)
    print("Completed Conversation.")
    print("Life Cycle State: {}".format(conversation.lifecycle_state))
    print("Conversation Profile Name: {}".format(conversation.conversation_profile))
    print("Name: {}".format(conversation.name))
    return conversation