Urgent.News

What's breaking now, across thousands of outlets.

Tech

The 24-Hour Window Decides Whether Your WhatsApp Reply Sends or Gets Rejected

There are exactly three ways to automate WhatsApp: rent a SaaS platform, wire up Meta's Cloud API yourself, or build on Google Sheets and Apps Script. I have built the third one, and what surprised me is how little that choice changes about the part that actually breaks. All three send through the same official Cloud API, and that API applies the same rule to all three. You may send a free-form…

WhatsApp offers three ways to automate its platform: using a SaaS service, setting up Meta's Cloud API independently, or employing Google Sheets and Apps Script. The author, who implemented the third method, discovered that the crucial factor in determining whether a WhatsApp reply is sent or rejected is a 24-hour window following the customer's latest message.

This window permits only free-form messages, while any message outside of it must be an approved template. All three automation methods rely on Meta's official Cloud API, which enforces the same rule for each method. The key question before sending any outbound message is whether the window is still open. If the code handling this check is incorrect, the result isn't a crash, but a missed reply or an unexpectedly charged template.

Here's the function that determines the reply mode, along with the three ways the author observed this function failing.

The first, obvious version fails in two ways. It incorrectly checks if the timestamp is more than 24 hours old by using JavaScript's Date object. However, `Date.now()` returns milliseconds, not seconds, causing the condition to always evaluate to false, sending all messages through as free-form. Additionally, parsing the timestamp as a Date object incorrectly results in NaN, causing the condition to always evaluate to false, also sending messages incorrectly.

The second, unforgiving version also stems from this same error but in the opposite direction. By storing JavaScript's Date.now() as milliseconds on one path and epoch seconds on another, the elapsed time calculation becomes a thousand times too small, interpreting the 24-hour window as forever open after it's closed. This leads to free-form replies being incorrectly rejected as templates, with no indication in the logs.

Both mistakes arise from the same issue: the API provides timestamps in multiple formats, none of which are normalized. A single normalizer is needed to convert any timestamp shape to epoch seconds, ensuring accurate calculations and preventing these issues.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Phones don’t have lights

Mark Zuckerberg has a new defense of the Ray-Ban Meta glasses: they're actually doing more to signal they're taking a photo than phones do.

More from Friday 25 September →