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:
@@ -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 !== '') {
|
||||
|
||||
Reference in New Issue
Block a user