- Implement Bird API client (`bird.php`) for handling HTTP requests to Bird services. - Add routes for voice and flash call management (`birdVoiceFlashCallsRoute.php`, `birdNumbersRoute.php`). - Introduce test cases for voice calls, flash calls, and numbers (`VoiceCallsApiTest.php`, `NumbersAndFlashCallsApiTest.php`). - Include configuration management classes and APIs for enabling the Bird module and managing API keys (`bird_c.php`). - Provide OpenAPI specifications for flash call endpoints (`bird-flash-calls.md`).
100 lines
4.4 KiB
PHP
100 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\bird;
|
|
use traits\route_t;
|
|
|
|
class birdVoiceCallsRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
// Create a voice call
|
|
$this->post('/bird/voice/calls', function () {
|
|
global $response;
|
|
// Permission: create/place a voice call via Bird
|
|
self::requirePermission('modules_bird_voice_calls_create');
|
|
$client = new bird();
|
|
// Require workspace/channel per Bird API docs
|
|
$ws = (string)($this->fromRequest('workspaceId') ?? '');
|
|
$ch = (string)($this->fromRequest('channelId') ?? '');
|
|
if ($ws === '' || $ch === '') {
|
|
$response->error('Missing required parameters: workspaceId, channelId', 400);
|
|
}
|
|
$base = '/workspaces/' . rawurlencode($ws) . '/channels/' . rawurlencode($ch) . '/calls';
|
|
$payload = $this->getParametersAsArray();
|
|
unset($payload['workspaceId'], $payload['channelId']);
|
|
$res = $client->sendPostRequest($base, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_calls_create' => 'Create/place a voice call via Bird',
|
|
]);
|
|
|
|
// List voice calls (passthrough of query filters)
|
|
$this->get('/bird/voice/calls', function () {
|
|
global $response;
|
|
// Permission: list voice calls via Bird
|
|
self::requirePermission('modules_bird_voice_calls_list');
|
|
$client = new bird();
|
|
$ws = (string)($this->fromQuery('workspaceId') ?? '');
|
|
$ch = (string)($this->fromQuery('channelId') ?? '');
|
|
if ($ws === '' || $ch === '') {
|
|
$response->error('Missing required parameters: workspaceId, channelId', 400);
|
|
}
|
|
$base = '/workspaces/' . rawurlencode($ws) . '/channels/' . rawurlencode($ch) . '/calls';
|
|
$query = $this->getParametersAsArray();
|
|
unset($query['workspaceId'], $query['channelId']);
|
|
$res = $client->sendGetRequest($base, $query);
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_calls_list' => 'List voice calls via Bird',
|
|
]);
|
|
|
|
// Get a specific call by ID
|
|
$this->get('/bird/voice/calls/{id}', function () {
|
|
global $response;
|
|
// Permission: get a specific voice call via Bird
|
|
self::requirePermission('modules_bird_voice_calls_get');
|
|
$client = new bird();
|
|
$id = (string)$this->fromRoute('id');
|
|
if ($id === null || $id === '') {
|
|
$response->error('Missing id', 400);
|
|
}
|
|
$ws = (string)($this->fromQuery('workspaceId') ?? '');
|
|
$ch = (string)($this->fromQuery('channelId') ?? '');
|
|
if ($ws === '' || $ch === '') {
|
|
$response->error('Missing required parameters: workspaceId, channelId', 400);
|
|
}
|
|
$base = '/workspaces/' . rawurlencode($ws) . '/channels/' . rawurlencode($ch) . '/calls';
|
|
$res = $client->sendGetRequest($base . '/' . rawurlencode($id));
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_calls_get' => 'Get a voice call by ID via Bird',
|
|
]);
|
|
|
|
// Hang up an active call by ID
|
|
$this->post('/bird/voice/calls/{id}/hangup', function () {
|
|
global $response;
|
|
// Permission: hang up a specific voice call via Bird
|
|
self::requirePermission('modules_bird_voice_calls_hangup');
|
|
$client = new bird();
|
|
$id = (string)$this->fromRoute('id');
|
|
if ($id === null || $id === '') {
|
|
$response->error('Missing id', 400);
|
|
}
|
|
$ws = (string)($this->fromRequest('workspaceId') ?? $this->fromQuery('workspaceId') ?? '');
|
|
$ch = (string)($this->fromRequest('channelId') ?? $this->fromQuery('channelId') ?? '');
|
|
if ($ws === '' || $ch === '') {
|
|
$response->error('Missing required parameters: workspaceId, channelId', 400);
|
|
}
|
|
$base = '/workspaces/' . rawurlencode($ws) . '/channels/' . rawurlencode($ch) . '/calls';
|
|
$res = $client->sendPostRequest($base . '/' . rawurlencode($id) . '/hangup', []);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_calls_hangup' => 'Hang up a voice call by ID via Bird',
|
|
]);
|
|
}
|
|
}
|