webhook連携やREST APIを使って取得した通話履歴情報のうち、録音のテキスト変換データを分類・処理する方法についてご案内します。
コールコネクトの録音では、発着信の分類や保留の有無によって、発話者のチャンネルが異なります。
担当者がどのチャンネルの発言に該当するかを以下の表で示します。
| transcribe_direction | transcribes | 担当者のチャンネル番号 |
| outbound_operator_right | JSONオブジェクト |
録音1はchannel-0 録音2以降はchannel-1 |
| outbound_operator_left | JSONオブジェクト |
録音1はchannel-1 録音2以降はchannel-0 |
| inbound_operator_right | JSONオブジェクト |
録音1はchannel-0 録音2以降はchannel-0 |
| inbound_operator_left | JSONオブジェクト |
録音1はchannel-1 録音2以降はchannel-1 |
| no_direction | - | 通話なし |
| - | null | 録音テキスト変換OFF設定 |
| - | { "REから始まる録音識別子": [] } | 変換中 or 1文字も識別できなかった |
※この条件は、回線提供元の通話・録音仕様により変更を受ける場合があります。
transcribesは、以下のJSONオブジェクト形式です。
保留ごとに録音が作成され、REから始まる識別子が割り当てられます。この識別子によって録音ごとのテキスト変換結果が割り当てられます。
各録音内では、チャンネル識別子、発言内容、発言開始したときの経過時間が出力されています。
{
"REから始まる録音識別子1": [
[チャンネル識別子,発言内容1,経過時間(秒)],
[チャンネル識別子,発言内容2,経過時間(秒)],
...
],
"REから始まる録音識別子2": [
...
],
...
}
例えば担当者の発言を収集したい場合、REST APIを使い以下のように処理できます。
データ取得後の処理方法については、webhookも同様です。
sample.js
var request = require('request');
const url = "通話履歴API > [/v1/records/{id}] > [Try it out!] で発行されるURL";
var headers = {
"Content-Type": "application/json",
"X-Callconnect-Token": "[管理] > [連携] > API で取得したトークン"
};
const option = {
"url": url,
"headers": headers,
"json": true
};
// 担当者channel参照テーブル
const whoIsAgent = {
"outbound_operator_right": ["channel-0", "channel-1"],
"outbound_operator_left": ["channel-1", "channel-0"],
"inbound_operator_right": ["channel-0", "channel-0"],
"inbound_operator_left": ["channel-1", "channel-1"]
};
request.get(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
const direction = body.transcribe_direction;
// 通話が成立しなかった場合 = transcribesが存在しない場合は、処理しない
if (direction == "no_direction") return;
// 番号設定で録音のテキスト変換OFFまたは1文字も変換できなかった場合は、処理しない
if (!body.transcribes || !Object.keys(body.transcribes).length) return;
const items = Object.entries(body.transcribes);
let i = 1;
for (const [key, speech] of items) {
// key は録音識別子のため、不使用です。
console.log(`--- ${i}番目の録音 ---`);
for (const phrase of speech) {
const agentChannel = whoIsAgent[direction][ (i==1) ? 0 : 1 ];
if (phrase[0] != agentChannel) continue;
console.log(`発言:${phrase[1]} | 経過時間[秒]:${phrase[2]}`);
}
i++;
}
} else {
console.log('error: '+ JSON.stringify(response));
}
});
コメント
0件のコメント
サインインしてコメントを残してください。