Add sayMessage method to Bird API client, extend birdVoiceWebhooksRoute with TTS capability for inbound calls, introduce /bird/voice/calls/{id}/say route, and update OpenAPI spec accordingly.

This commit is contained in:
Jeppe Bundgaard
2026-03-04 12:47:44 +01:00
parent 37f0f280d8
commit 96629cba0d
4 changed files with 183 additions and 224 deletions
+33
View File
@@ -296,6 +296,33 @@ class bird
return $this->sendPostRequest($base . '/' . rawurlencode($callId) . '/hangup', $payload);
}
public function sayMessage(string $workspaceId, string $channelId, string $callId, array $payload): array|object|null
{
$this->logBirdAction('BIRD_VOICE_CALL_SAY', 'workspace=' . $workspaceId . ' channel=' . $channelId . ' call=' . $callId);
/**
* Example payload:
* https://api.bird.com/workspaces/{workspaceId}/channels/{channelId}/calls/{callId}/say
* {
* "text": "text",
* "locale": "en-US",
* "voice": "text",
* "loop": 1,
* "timeout": 1
* }
*/
if (!isset($payload['text']) || !is_string($payload['text']) || trim($payload['text']) === '') {
throw new Exception('The "text" field is required in the payload and must be a non-empty string');
}
return $this->sendPostRequest($this->sayBase($workspaceId, $channelId, $callId), [
// Default values
'locale' => 'da-DK',
'voice' => 'text',
'loop' => 1,
'timeout' => 1,
...$payload,
]);
}
public function listNumbers(string $workspaceId, array $query = []): array|object|null
{
$this->logBirdAction('BIRD_NUMBERS_LIST', 'workspace=' . $workspaceId . ' query_keys=' . implode(',', array_keys($query)));
@@ -409,6 +436,12 @@ class bird
return '/workspaces/' . rawurlencode($workspaceId) . '/channels/' . rawurlencode($channelId) . '/calls';
}
private function sayBase(string $workspaceId, string $channelId, string $callId): string
{
// https://api.bird.com/workspaces/{workspaceId}/channels/{channelId}/calls/{callId}/say
return '/workspaces/' . rawurlencode($workspaceId) . '/channels/' . rawurlencode($channelId) . '/calls/' . rawurlencode($callId) . '/say';
}
private function extractId(array|object|string|null $response): ?string
{
if (is_object($response) && isset($response->id) && is_string($response->id) && $response->id !== '') {