whatsapp-api icon indicating copy to clipboard operation
whatsapp-api copied to clipboard

Can We Send a Media With the text Caption in Message ?

Open vijaygopal97 opened this issue 9 months ago • 3 comments

We usually Send Images or Video with a written message in Whatsapp, is It possible To Send That using this API ? As Far As I can Read from the API Documentation, Only Sending Separately is made possible in it. Can you please confirm if its Possible to send both together or not?

vijaygopal97 avatar Apr 02 '25 12:04 vijaygopal97

Already discussed here https://github.com/chrishubert/whatsapp-api/issues/111

avoylenko avatar Apr 02 '25 13:04 avoylenko

@avoylenko there is an issue the implementation:

if (options?.media) {
          const media = options.media
          media.filename = null
          media.filesize = null
          options.media = new MessageMedia(media.mimetype, media.data, media.filename, media.filesize)
        }
        messageOut = await client.sendMessage(chatId, content, options)

On file: https://github.com/avoylenko/whatsapp-api/blob/master/src/controllers/clientController.js#L78

As we can see here, it forces the filename to be null. It should follow the proper filename "or null", and if "null" maybe we should add an empty value instead (like media.filename = media?.filename || '';)

Image

Don't know why the decision to force it to be null, and seems like it comes from your original implementation https://github.com/avoylenko/whatsapp-api/commit/d3baebd150cd255bf69b6719e6021041ab04526f

So I believe we should open a PR to fix this? (or not sure if this is okay?)

asfo avatar Apr 08 '25 21:04 asfo

@asfo Seems like my initial commit was changed by SonarQube.

Fix is available in forked project: https://github.com/avoylenko/wwebjs-api

Also feel free to open PR here, @chrishubert might approve it someday.

avoylenko avatar Apr 09 '25 18:04 avoylenko