Twilioで着信コールを受け入れます
コール受け入れ、拒否、切断、ミュートなどのコール関連操作はすべて、コール・オブジェクトで実行する必要があります。 call.accept()
関数を使用して、コールを受け入れます。
次のフロー図は、エージェントがFusionまたはメディア・ツールバー・アプリケーションからのコールを受け入れると実行される一連の操作を示しています:
- エージェントは、Fusionアプリケーションまたはメディア・ツールバー・アプリケーションからコールを受け入れることができます。 エージェントがFusionアプリケーションの「回答」ボタンをクリックすると、
onToolbarInteractionCommand
イベントがacceptコマンドで起動されます。 エージェントがメディア・ツールバー・アプリケーションからのコールを受け入れると、そのコールを受け入れるサプライヤAPIが直接コールされます。 - メディア・ツールバー・アプリケーションは、このイベントを受信し、イベントがコールを受け入れる場合は、コールを受け入れるTwilio APIをコールできます。
- CTIサプライヤがメディア・ツールバー・アプリケーションにコールが受諾されたことを通知すると、パートナ・アプリケーションは
startCommEvent
アクションを起動できます。 - Fusionアプリケーションがこのアクションを識別すると、一致した担当者とエンゲージメント・パネルが、スクリーン・ポップのFusion構成管理で構成されたルールに基づいて開きます。 詳細は、「スクリーン・ポップ・ページの構成」を参照してください。
受信イベント中に、イベント・ペイロードからTwilio.Call
オブジェクトを受信します。 call.accept()
関数を使用すると、次の例に示すようにコールを受け入れることができます:
public async acceptCall(): Promise<void> {
if (this.call) {
this.call.accept();
}
}
vendorHandler.ts
ファイルのacceptCall
関数を変更して、call.accept()
関数をコールします。
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> {
if (this.call) {
this.call.accept();
}
}
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アプリケーションにサインインします。 メディア・ツールバーを開き、「エージェント可用性」ボタンをクリックしてエージェントをコールに使用できるようにします。 次に、カスタマ・ケア番号へのコールを開始します。 着信コール通知は、メディア・ツールバー・アプリケーションおよびFusionアプリケーション・ウィンドウで受信します。 メディア・ツールバー・アプリケーションから、またはFusionアプリケーションから、またはSoftphoneアプリケーションからコールを受け入れることができます。 コールを受け入れると、メディア・ツールバーの状態がACCEPTED状態に変わり、エンゲージメントがFusionアプリケーションで開きます。