Skip to content

Commit

Permalink
Fixed captions on whatsapp audio (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Nov 8, 2024
1 parent b1399d3 commit fac2469
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/Messages/MessageObjects/AudioObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@

class AudioObject implements ArrayHydrateInterface
{
public function __construct(private string $url, private string $caption = '')
/**
* Legacy to pass in a caption as this should never have been supported. Nothing will happen if you pass one in.
*/
public function __construct(private string $url, private readonly ?string $caption = null)
{
}

public function fromArray(array $data): AudioObject
{
$this->url = $data['url'];

if (isset($data['caption'])) {
$this->caption = $data['caption'];
}

return $this;
}

public function toArray(): array
{
$returnArray = [
return [
'url' => $this->url
];

if ($this->caption) {
$returnArray[] = [
'caption' => $this->caption
];
}

return $returnArray;
}

public function getUrl(): string
{
return $this->url;
}

/**
* @deprecated Unsupported
* @return string
*/
public function getCaption(): string
{
trigger_error(
'Captions are not supported in this API, this will error at server level.',
E_USER_DEPRECATED
);

return $this->caption;
}
}
2 changes: 1 addition & 1 deletion test/Messages/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function testCanSendWhatsAppAudio(): void
{
$audioObject = new AudioObject(
'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
'some audio'
null
);

$payload = [
Expand Down

0 comments on commit fac2469

Please sign in to comment.