Skip to content

Commit

Permalink
parseCallRecordArray
Browse files Browse the repository at this point in the history
  • Loading branch information
yparitcher committed Nov 26, 2024
1 parent 650b07b commit a3a7520
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/RingCentral.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public function verifyWebhook(Request $request): bool {
}

public function parseWebhookBody(Request $request): Fluent {
$sessionId = $request->input('body.sessionId');
$timestamp = $request->date('timestamp');
$direction = $request->enum('body.parties.0.direction', CallDirection::class);
$extensionId = $request->input('body.parties.0.extensionId');
Expand All @@ -294,6 +295,28 @@ public function parseWebhookBody(Request $request): Fluent {
$externalKey = $direction == CallDirection::INBOUND ? 'from' : 'to';
$externalPhoneNumber = $request->string("body.parties.0.{$externalKey}.phoneNumber")->ltrim('+1');
return fluent([
'sessionId' => $sessionId,
'timestamp' => $timestamp,
'direction' => $direction,
'extensionId' => $extensionId,
'extensionEmail' => $extensionEmail,
'recordingId' => $recordingId,
'externalPhoneNumber' => $externalPhoneNumber,
]);
}

public function parseCallRecordArray(array $record): Fluent {
$record = new Fluent($record);
$sessionId = $record->get('sessionId');
$timestamp = Carbon::parse($record['startTime']);
$direction = CallDirection::from($record->get('direction'));
$extensionId = $record->get('extension.id');
$extensionEmail = $this->getExtensionMap()->get($extensionId);
$recordingId = $record->get('recording.id');
$externalKey = $direction == CallDirection::INBOUND ? 'from' : 'to';
$externalPhoneNumber = Str::ltrim($record->get("{$externalKey}.phoneNumber"), '+1');
return fluent([
'sessionId' => $sessionId,
'timestamp' => $timestamp,
'direction' => $direction,
'extensionId' => $extensionId,
Expand Down

0 comments on commit a3a7520

Please sign in to comment.