- 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`).
124 lines
5.9 KiB
PHP
124 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\bird;
|
|
use traits\route_t;
|
|
|
|
class birdVoiceFlashCallsRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
// Create a flash call
|
|
$this->post('/bird/voice/flash-calls', function () {
|
|
global $response;
|
|
// Permission: create/place a flash call via Bird
|
|
self::requirePermission('modules_bird_voice_flash_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) . '/flashcalls';
|
|
$payload = $this->getParametersAsArray();
|
|
unset($payload['workspaceId'], $payload['channelId']);
|
|
$res = $client->sendPostRequest($base, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_create' => 'Create/place a flash call via Bird',
|
|
]);
|
|
|
|
// List flash calls
|
|
$this->get('/bird/voice/flash-calls', function () {
|
|
global $response;
|
|
// Permission: list flash calls via Bird
|
|
self::requirePermission('modules_bird_voice_flash_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) . '/flashcalls';
|
|
$query = $this->getParametersAsArray();
|
|
unset($query['workspaceId'], $query['channelId']);
|
|
$res = $client->sendGetRequest($base, $query);
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_list' => 'List flash calls via Bird',
|
|
]);
|
|
|
|
// Get a specific flash call by ID
|
|
$this->get('/bird/voice/flash-calls/{id}', function () {
|
|
global $response;
|
|
// Permission: get a specific flash call via Bird
|
|
self::requirePermission('modules_bird_voice_flash_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) . '/flashcalls';
|
|
$res = $client->sendGetRequest($base . '/' . rawurlencode($id));
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_get' => 'Get a flash call by ID via Bird',
|
|
]);
|
|
|
|
// Complete/end a flash call by ID (POST to the resource)
|
|
$this->post('/bird/voice/flash-calls/{id}', function () {
|
|
global $response;
|
|
// Permission: complete/end a flash call via Bird
|
|
self::requirePermission('modules_bird_voice_flash_calls_end');
|
|
$client = new bird();
|
|
$id = (string)$this->fromRoute('id');
|
|
if ($id === null || $id === '') {
|
|
$response->error('Missing id', 400);
|
|
}
|
|
// Forward any body fields (e.g., result/status) transparently
|
|
$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) . '/flashcalls';
|
|
$payload = $this->getParametersAsArray();
|
|
unset($payload['workspaceId'], $payload['channelId']);
|
|
$res = $client->sendPostRequest($base . '/' . rawurlencode($id), $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_end' => 'Complete/end a flash call by ID via Bird',
|
|
]);
|
|
|
|
// Complete/end a flash call by using from/to numbers
|
|
$this->post('/bird/voice/flash-calls/end', function () {
|
|
global $response;
|
|
// Permission: complete/end a flash call by numbers via Bird
|
|
self::requirePermission('modules_bird_voice_flash_calls_end_by_numbers');
|
|
$client = new bird();
|
|
$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) . '/flashcalls';
|
|
$payload = $this->getParametersAsArray();
|
|
unset($payload['workspaceId'], $payload['channelId']);
|
|
// Basic validation hints: expect 'from' and 'to' but let Bird validate strictly
|
|
$res = $client->sendPostRequest($base . '/end', $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_end_by_numbers' => 'Complete/end a flash call using from/to numbers via Bird',
|
|
]);
|
|
}
|
|
}
|