機械翻訳について

着信コール通知をTwilioに表示

Twilioは、Twilio.Deviceオブジェクトから受信イベントを起動して、メディア・ツールバー・アプリケーションへの着信コールを通知します。 メディア・ツールバー・アプリケーションから、このイベントが受信されると、このイベントをリスニングし、必要なステップを実行します。

次のフロー図は、顧客がサービス・センターの電話番号にダイヤルした後に実行される一連の操作を示しています:

Twilioの着信コール・シナリオを示す図。

仕組み:

  1. Twilioは、着信コール通知を受信し、Twilio.Call型のペイロードとしてコール情報とともに着信イベントを起動します。 Twilioはこのステップを担当します。
  2. ツールバー・アプリケーションの受信イベント・ハンドラは、コール・ペイロードとともにこのイベントを受信します。)
  3. newCommイベントは、ツールバー・アプリケーションから起動されます。
  4. Fusionアプリケーションは、このアクションを識別すると、担当者番号参照を実行し、アクション・レスポンスの担当者詳細を返します。

    独自のデフォルト逆参照を作成するための参照フィルタを作成するには、「参照フィルタの作成」を参照してください。

  5. 最後に、Fusionアプリケーションは、ダイアログ・ボックスを介して着信コール・オファー通知についてエージェントに通知します。
  6. エージェントが通話に応答または拒否できるようになりました。

これを行うには、vendorHandler.tsファイルのmakeAgentAvailable関数でTwilio.Deviceオブジェクトが初期化されると、次のコードを追加します。

ノート: vendorHandler.tsファイルのmakeAgentAvailable関数でTwilio.Deviceオブジェクトが初期化されると、次のコードを追加します。
this.device.on("incoming", this.incomingCallCallback);

表示されるコードから、incomingCallCallbackは、Twilio.Device受信イベント中に実行されるコールバック関数です。 この関数は、vendorHandler.tsファイルで次のように定義します:

public incomingCallCallback = (call: Call) => {
    this.integrationEventsHandler.incomingCallHandler(call.parameters.From, call.parameters.CallSid);
    this.call = call;
}

acceptCallrejectCallhangupCallなどのコール関連操作は、受信イベント・リスナーで受信したコール・オブジェクトに対して実行されます。

vendorHandler.tsファイルのサンプル・コード

着信コール通知を表示するためのvendorHandler.tsファイルの完全なコードを次に示します:

import { Call, Device } from '@twilio/voice-sdk';
import { ICtiVendorHandler } from './ICtiVendorHandler';
import { IntegrationEventsHandler } from '../integrationEventsHandler';
 
export class VendorHandler implements ICtiVendorHandler {
    private twilio: any;
    private device: Device | null;
    private integrationEventsHandler: IntegrationEventsHandler;
    private call: Call | null;
    public idAndToken: any;
 
    constructor(integrationEventsHandler: IntegrationEventsHandler) {
        this.twilio = (window as any).Twilio;
        this.device = null;
        this.idAndToken = null;
        this.integrationEventsHandler = integrationEventsHandler;
        this.call = null;
    }
 
    public async makeAgentAvailable(): Promise<void> {
        this.idAndToken = await this.getIdAndToken();
        this.device = new this.twilio.Device(this.idAndToken.token, {
            logLevel: 1,
            codecPreferences: ["opus", "pcmu"],
            enableRingingState: true
        });
        let resolve: Function;
        let reject: Function;
        if (this.device) {
            this.device.on("registered", () => {
                console.log("Registration completed ...")
                resolve();
            });
            this.device.on("error", (deviceError) => {
                console.error("Registration Failed ...", deviceError);
                reject();
            });
 
            this.device.on("incoming", this.incomingCallCallback);
 
            this.device.register();
        }
        return new Promise((res: Function, rej: Function) => {
            resolve = res;
            reject = rej;
        });
    }
 
    public incomingCallCallback = (call: Call) => {
        this.integrationEventsHandler.incomingCallHandler(call.parameters.From, call.parameters.CallSid);
        this.call = call;
    }
    public async makeAgentUnavailable(): Promise<void> {
        let resolve: Function;
        let reject: Function;
        if (this.device) {
            this.device.on("unregister", () => {
                console.log("Successfully UnRegistered ...")
                resolve();
            });
            this.device.on("error", (deviceError) => {
                console.error("Failed to unregister ...", deviceError);
                reject();
            });
            this.device.unregister();
        }
        return new Promise((res: Function, rej: Function) => {
            resolve = res;
            reject = rej;
        });
    }
    public async makeOutboundCall(phoneNumber: string, eventId: string): Promise<void> {
        throw new Error('Method not implemented.');
    }
    public async acceptCall(): Promise<void> {
        throw new Error('Method not implemented.');
    }
    public async rejectCall(): Promise<void> {
        throw new Error('Method not implemented.');
    }
    public async hangupCall(): Promise<void> {
        throw new Error('Method not implemented.');
    }
 
    private async getIdAndToken(): Promise<any> {
        const headers: Headers = (new Headers()) as Headers;
        headers.set('Accept', 'application/json');
        const request: Request = new Request('https://twilio-voice-stream.com/token', {
            method: 'GET',
            headers: headers
        }) as Request;
        const idAndToken: Response = await fetch(request);
        this.idAndToken = await idAndToken.json();
        return this.idAndToken;
    }
}

進捗の確認

これらのステップが終了したら、OJETサーバーを使用してアプリケーションを起動し、Fusionアプリケーションにサインインします。 メディア・ツールバーを開き、「エージェント可用性」ボタンをクリックしてエージェントをコールに使用できるようにします。 次に、カスタマ・ケア番号へのコールを開始します。 この間、メディア・ツールバーの状態がRINGING状態に変更され、メディア・ツールバー・アプリケーションで着信コール通知を確認できます。