Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error sending message: Error: Header image must not have a caption #198

Closed
HysMX opened this issue Aug 16, 2023 · 10 comments · Fixed by #203
Closed

Error sending message: Error: Header image must not have a caption #198

HysMX opened this issue Aug 16, 2023 · 10 comments · Fixed by #203
Labels
bug Something isn't working

Comments

@HysMX
Copy link

HysMX commented Aug 16, 2023

Describe the bug
An error in console while trying to send a broadcast message

To Reproduce
Steps to reproduce the behavior:

const image = new Image("https://i.imgur.com/RZ1MmvC.png")
const button = new Interactive(
  new ActionButtons(
    new Button("button_quote_offer", "Responder"),
    new Button("button_quote_ignore", "Ignorar")
  ),
  new Body(`*Nueva Solicitud*
*Cliente:* ${customer?.name}
*Solicitud:* ${prompt}
*Producto / Servicio:*: ${product}
*Categoría:* ${category}
*Presupuesto:* ${price}
  `),
  new Header(image)
);
      
const responses = await Whatsapp.broadcastMessage(PHONE_ID, recipients, button);

Promise.all(responses).then(console.log);    

Expected behavior
Send the message with the image header

It was sending the message just fine until i updated the library to the latest version, the code is unmodified

@HysMX
Copy link
Author

HysMX commented Aug 16, 2023

Downgraded to 1.0.2 and worked just fine
image

@Secreto31126
Copy link
Owner

Secreto31126 commented Aug 17, 2023

This is a really weird issue. The diff between 1.0.2..1.0.3 only includes changes for template.ts (ignoring the modified .md files), so your code shouldn't be affected by the update...

I will test your snippet in a few hours and try to find the solution.

Thanks!

@Secreto31126
Copy link
Owner

Secreto31126 commented Aug 18, 2023

I managed to replicate the issue, and to my surprise it's REALLY weird.

Given this snippet:

const image = new Image("https://i.imgur.com/RZ1MmvC.png");
console.log(image);

The obtained output on 1.0.2 is:

{ link: 'https://i.imgur.com/RZ1MmvC.png' }

However, on 1.0.3 (and v2), the terminal logs the following:

{
  id: undefined,
  link: 'https://i.imgur.com/RZ1MmvC.png',
  caption: undefined
}

Which is really annoying, because the library uses the keyword in to check if the class contains such property. Although undefined, the property is in the object, hence throwing the error as it thinks the image contains a caption.

My only guess for this issue is a breaking dev dependecy update. I will try to find out which one and see if it's intentional or not. IIRC, esbuild had a mid version update, so maybe the issue is there.

This is why people write unit tests :)

Thanks for opening the issue.


Update

I unfortunately found the broken dependecy: esbuild@18

#166
evanw/esbuild#2993
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

There's an easy solution, which would be setting useDefineForClassFields to true on tsconfig, but I'm not certain it's the right answer.

@Secreto31126 Secreto31126 added the bug Something isn't working label Aug 18, 2023
@Secreto31126 Secreto31126 mentioned this issue Aug 20, 2023
4 tasks
@Secreto31126
Copy link
Owner

Secreto31126 commented Aug 20, 2023

Hi, I just published 1.0.4 to npm with a bug fix.

Let me know if it works!

@HysMX
Copy link
Author

HysMX commented Aug 24, 2023

The error persists on 1.0.4 its weird because logging the image object only returns the URL
image

Image Object
image

Code:

        const image = new Image("https://i.imgur.com/CFpN5kh.png");
        console.log(JSON.stringify(image), "imagen 2")
        const button = new Interactive(
          new ActionButtons(
            new Button("button_menu_seller", "Vendedor"),
            new Button("button_menu_buyer", "Comprador")
          ),
          new Body(`¡Bienvenido de nuevo ${customer.name}! ¿Qué menu deseas visualizar?`),
          new Header(image)
        );
        await Whatsapp.sendMessage(PHONE_ID as string,message.from, button);

@Secreto31126
Copy link
Owner

That's unfortunate. Seems like a full update will be necessary. I will do it later today.

@HysMX
Copy link
Author

HysMX commented Aug 24, 2023 via email

@Secreto31126
Copy link
Owner

Wow, eso sería increíble. Si realmente creés que vale la pena, podés usar Patreon:

https://patreon.com/Secreto31126

Muchísimas gracias 😁.

(Sí, el dólar es un caos acá 😂)

@Secreto31126
Copy link
Owner

Secreto31126 commented Aug 24, 2023

I just did a full rewrite of the property checks and published to the beta tag (npm i whatsapp-api-js@beta), let me know if the issue is fixed for you!

@Secreto31126
Copy link
Owner

Based on my white box tests I believe the issue is fixed, so I will publish to npm and close the issue.

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants