ヘッドレス ウェブ SDK ガイド

ヘッドレス ウェブ SDK を使用すると、ニーズに応じて会社のサポート エクスペリエンスを柔軟に拡張、カスタマイズできます。これには、おなじみの ウェブ SDK 機能がすべて含まれており、それらをサポートする UI と UX を構築できます。

ヘッドレス ウェブ SDK をインストールして使用するには、組織のウェブ デベロッパー チームのサポートが必要です。統合を成功させ、最適なパフォーマンスを実現するには、資格のある担当者を関与させることをおすすめします。

ソフトウェア開発の文脈では、「ヘッドレス」とは、フロントエンドのプレゼンテーション レイヤ(「ヘッド」)がバックエンドのロジックと機能から分離された、分離されたアーキテクチャを指します。ヘッドレス アーキテクチャでは、バックエンド(「ヘッドレス」部分とも呼ばれます)が、その機能とサービスを使用できるようにする API を提供します。

たとえば、カスタム ワークフローの自動化などです。エンドユーザーがチャットを開始すると、on("chat.message") イベントがトリガーされます。受信した特定のチャット メッセージに基づいて、カスタム自動化トリガーを定義できます。たとえば、エンドユーザーがチャットに「エスカレーション」と入力すると、イベント ハンドラはチャット セッションを上位のサポートチームに自動的にエスカレーションし、重要な問題に迅速に対応できます。

このガイドでは、SDK のインストール プロセス、統合機能、使用方法について説明します。API の使用方法の詳細については、ヘッドレス ウェブ SDK API ドキュメントをご覧ください。利用可能なイベントのリストは、[イベント] ページで確認できます。

ヘッドレス ウェブ SDK をインストールする

ヘッドレス ウェブ SDK クライアントをインストールするには、プロジェクトで次のコード スニペットを使用します。

npm を使用してパッケージをインストールできます。

npm install @ujet/websdk-headless --save

または、UJET がホストするスクリプトを使用することもできます。

<script src="https://websdk.ujet.co/v3/headless.js"></script>

<script>
  // The hosted script exposes the client as the global `UJETClient`.
  // const client = new UJETClient(...)
</script>

ヘッドレス ウェブ SDK を使用する

ヘッドレス Web SDK を使用するには、提供されているサンプルコードに沿って操作します。

import { Client } from "@ujet/websdk-headless"

async function authenticate() {
  const resp = await fetch("/your-auth-endpoint")
  const data = await resp.json()
  return { token: data.token }
}

const client = new Client({
  companyId: "YOUR-COMPANY-ID",
  tenant: "YOUR-TENANT-NAME",
  authenticate: authenticate,
})

// const company = await client.getCompany()
// const menus = await client.getMenus()

Client クラスは、いくつかのオプションを受け入れます(要件に応じてカスタマイズできます)。

interface ClientOption {
  companyId: string;
  authenticate: () => Promise<TokenResponse>;
  tenant?: string;
  host?: string;
  lang?: string;
  bridge?: string;
  version?: string;
  cobrowse?: {
    enabled?: boolean;
    messages?: CobrowseMessages;
    api?: string;
    license?: string;
    trustedOrigins?: string[];
    capabilities?: string[];
    registration?: boolean;
    redactedViews?: string[];
    unredactedViews?: string[];
    template?: string;
  };
}

ロギングを有効にする

実装とテストの段階では、コンソールログで追加情報を収集する必要がある場合があります。ヘッドレス SDK のロギングを有効にするには、ウェブ アプリケーションに次のコードを追加して Logger と consoleLoggerHandler をインポートします。

import {Logger, consoleLoggerHandler } from '@ujet/websdk-headless'
Logger.addHandler(consoleLoggerHandler)

画面共有を設定する

ヘッドレス ウェブ SDK を使用して、画面共有を有効にして構成できます。

次のコードサンプルは、画面共有を有効にする方法を示しています。

new Client({
  // ...
  cobrowse: {
    enabled: true,
    license: 'YOUR_SCREEN_SHARE_LICENSE'
  }
})

次のコードサンプルは、画面共有のオプションを示しています。

interface CobrowseOption {
  enabled?: boolean
  // Widget-only - the following template + root options have no effect in the Headless SDK:
  template?: string
  confirmSessionTemplate?: string
  confirmRemoteControlTemplate?: string
  confirmFullDeviceTemplate?: string
  sessionControlsTemplate?: string
  root?: Element
  messages?: {
    confirmSessionTitle: string;
    confirmSessionContent: string;
    confirmRemoteControlTitle: string;
    confirmRemoteControlContent: string;
    confirmFullDeviceTitle: string;
    confirmFullDeviceContent: string;
    allowText: string;
    denyText: string;
    endSessionText: string;
  }
  api?: string
  license?: string
  trustedOrigins?: string[]
  capabilities?: string[]
  registration?: boolean
  redactedViews?: string[]
  unredactedViews?: string[]
  // Headless consent callbacks
  confirmSession?: () => Promise<boolean>
  confirmRemoteControl?: () => Promise<boolean>
  confirmFullDevice?: () => Promise<boolean>

  // Headless session-control callbacks
  showSessionControls?: () => void
  hideSessionControls?: () => void

  // Existing CobrowseIO instance
  instance?: any
}

カスタム テンプレート

上記のコードサンプルの template オプションを使用して、画面共有ダイアログ テンプレートをカスタマイズできます。

次の例は、デフォルトのテンプレートを示しています。

<dialog open class="cobrowse-dialog">
  <h1>$title</h1>
  <div class="cobrowse-dialog_content">$content</div>
  <div class="cobrowse-dialog_footer">
    <button class="cobrowse-dialog_allow js-cobrowse-allow">$allow</button>
    <button class="cobrowse-dialog_deny js-cobrowse-deny">$deny</button>
  </div>
</dialog>

このテンプレートを使用して、以下についてエンドユーザーに承認をリクエストするダイアログを構成できます。

  • 画面共有セッションを開始する

  • リモート コントロールの画面共有セッションを開始する

  • デバイス全体の画面共有セッションを開始する

テンプレートのオプションは次のとおりです。

  • confirmSessionTemplate: 画面共有セッションを確認する場合。

  • confirmRemoteControlTemplate: リモート コントロールの画面共有セッションを確認します。

  • confirmFullDeviceTemplate。デバイス全体の画面共有セッションを確認する場合。

  • sessionControlsTemplate: セッション コントロール ボタン。デフォルトのテンプレートは次のとおりです。 <button class="cobrowse-end js-cobrowse-end">$end</button>

メッセージ

カスタム テンプレートでは、次のメッセージ変数が使用されます。

  • $title

  • $content

  • $allow

  • $deny

次の例は、これらの変数の適用方法を示しています。

{
  confirmSessionTitle: string;  // $title
  confirmSessionContent: string;  // $content
  confirmRemoteControlTitle: string;  // $title
  confirmRemoteControlContent: string;  // $content
  confirmFullDeviceTitle: string;  // $title
  confirmFullDeviceContent: string;  // $content
  allowText: string;  // $allow
  denyText: string;  // $deny
  endSessionText: string;  // $end
}

次の例は、デフォルトの英語の変数値を表しています。

{
  "confirmSessionTitle": "Screen Share Session Request",
  "confirmSessionContent": "Do you want to share your current screen with the agent?",
  "endSessionText": "End Screen Share Session",
  "confirmRemoteControlTitle": "Remote Access Request",
  "confirmRemoteControlContent": "The agent would like to have access to your currently shared screen to further assist you. Do you want to allow this?",
  "confirmFullDeviceTitle": "Screen Share Request",
  "confirmFullDeviceContent": "Do you want to share your full screen with the agent? The agent will not be able to control anything on the screen.",
  "allowText": "Allow",
  "denyText": "Deny"
}

ヘッドレス クライアント API

import { Client } from "@ujet/websdk-headless"

イベント

出力されるすべてのイベントの一覧については、イベントのページをご覧ください。

プロパティ

名前 説明
deviceId デバイスの ID。初期化時にヘッドレス SDK によって決定されます。
lang 現在のクライアントの言語設定。構成で lang が渡されると、読み取り専用になります。
chat 進行中のチャットがある場合にのみ値が設定されます。
cobrowse 基盤となる CobrowseIO クライアント。cobrowse が初期化された後に使用可能になります。

イベント

出力されるすべてのイベントのリストについては、利用可能なすべてのイベントのページをご覧ください。

名前 説明
destroy コミュニケーターとすべてのイベント リスナーを破棄します。
on 指定されたイベントのイベント ハンドラを追加します。
off 指定されたイベントのイベント ハンドラを削除します。

.destroy メソッドを使用して、iframe とすべてのイベント リスナーを削除します。

client.destroy()

.on メソッドを使用してイベントをトラッキングします。

client.on('chat.updated', someFunc)

.off を使用してイベント ハンドラを削除します。

client.off('chat.updated', someFunc)

リファレンス実装

ウェブ SDK のリファレンス実装については、GitHub の ccaas-web-headless-sdk-sample をご覧ください。

このリポジトリには、CCAI Platform Web Headless SDK を使用して構築されたチャット アプリケーションのデモが含まれています。このサンプルは、Node.js バックエンドが安全な認証と構成の配信を処理し、純粋な JavaScript フロントエンドがチャット ユーザー インターフェースを提供する、基本的なクライアント サーバー アーキテクチャを示しています。