Files
api/services/nginx/app/routes/birdVoiceWebhooksRoute.php
T

42 lines
1.7 KiB
PHP

<?php
namespace routes;
use classes\bird;
use classes\slack;
use traits\bird_route_helpers_t;
use traits\route_t;
class birdVoiceWebhooksRoute
{
use route_t, bird_route_helpers_t;
public function run(): void
{
// Handle incoming voice call webhooks from Bird (and any other call webhooks that can be triggered via Bird)
$this->post('/bird/voice/calls/webhook/inbound', function () {
global $response;
// Permission: trigger a voice call via Bird webhooks (intended for incoming call webhooks, but can be used for any call webhooks)
self::requirePermission('modules_bird_voice_call_webhooks_trigger');
$client = new bird();
// Require workspace/channel per Bird API docs
$ws = $this->normalizeOptionalString($this->fromRequest('workspaceId') ?? $this->fromQuery('workspaceId'));
$ch = $this->normalizeOptionalString($this->fromRequest('channelId') ?? $this->fromQuery('channelId'));
if ($ws === '') {
$ws = $this->getConfiguredWorkspaceId($client);
}
if ($ch === '') {
$ch = $this->getConfiguredChannelId($client);
}
if ($ws === '' || $ch === '') {
$response->error('Missing required parameters: workspaceId, channelId', 400);
}
$payload = $this->getParametersAsArray();
$slack = new Slack();
$slack->send_message('Webhook received for incoming voice call: ' . json_encode($payload), 'Bird Voice Call Webhooks');
$response->success($res ?? ['status' => 'ok']);
}, [
'modules_bird_voice_call_webhooks_trigger' => 'Trigger a voice call via Bird webhooks',
]);
}
}