vonage-php-sdk-core icon indicating copy to clipboard operation
vonage-php-sdk-core copied to clipboard

Passing captions to WhatsApp audio messages throws an exception

Open ash-jc-allen opened this issue 2 years ago • 0 comments

Expected Behavior

I don't think you should be able to pass a caption for an audio message in WhatsApp. From looking at the docs, I get the impression that this is also the case (https://developer.vonage.com/messages/code-snippets/whatsapp/send-audio).

However, I'm new to tinkering with this API. So I apologise if I'm wrong! 😄

Current Behavior

It appears that if you pass a caption parameter to the Vonage\Messages\MessageObjects\AudioObject object, it will cause an API validation error because the caption field is unexpected.

Possible Solution

I'm probably not the best person to suggest a change for this. But my initial guess is that the AudioObject's toArray method should just ignore the caption field and not include it in the returned array. I think this could avoid a breaking change. But I guess this might confuse devs though if they're passing the caption field and not seeing it anywhere in the received WhatsApp message?

But, I think the long-term fix might be to completely remove all mentions of the caption field in the AudioObject.

Steps to Reproduce (for bugs)

I've been using this code here to reproduce the issue:

$whatsAppMessage = new WhatsAppAudio(
    to: 'NUMBER_GOES_HERE',
    from: 'NUMBER_GOES_HERE',
    audioObject: new AudioObject(
        url: 'AUDIO_URL_HERE',
        caption: 'CAPTION_HERE', // This line causes the error!
    ),
);

app(Client::class)
    ->messages()
    ->send($whatsAppMessage);

Context

I'm not currently using this in a real-world application. I was just writing an article about how to send WhatsApp messages from your Laravel app using Vonage.

Your Environment

  • Environment name and version (e.g. PHP 7.2 on nginx 1.19.1): PHP 8.1
  • Operating System and version: MacOS Ventura

Using the following Vonage packages in my Laravel app:

  • vonage/client - 3.0.0
  • vonage/client-core - 3.1.5
  • vonage/nexmo-bridge - 0.1.1
  • vonage/vonage-laravel - 1.0.0

I hope I've given enough info, but if you need anything else, feel free to give me a shout and I'll try to get back to you 🙂

ash-jc-allen avatar Dec 16 '22 01:12 ash-jc-allen