Send a message

Three kinds of message, and one WhatsApp rule that decides which one you may send.

The 24-hour window

WhatsApp does not let a business message anyone it likes, whenever it likes.

  • If the user messaged you in the last 24 hours, you can send free-form text.
  • Otherwise you can only send a template Meta has already approved.

Sending text outside the window fails with window_expired. That is WhatsApp's rule, not ours, and there is no way around it.

A test key ignores the window — see Test keys and the sandbox.

Text

await msg.messages.send({
  to: "+919812345678",
  type: "text",
  text: "Your order has shipped.",
});

Templates

Pre-approved messages with placeholders. These work at any time.

await msg.messages.send({
  to: "+919812345678",
  type: "template",
  templateId: "tpl_...",
  variables: { name: "Asha", order: "A-1029" },
});

Only approved templates send. See Create a template.

Media

Send the med_ id you got from Upload media, not the bytes.

await msg.messages.send({
  to: "+919812345678",
  type: "media",
  mediaId: "med_7c1d2e3f...",
  caption: "Your invoice",
});

Delivery status

send returns immediately with status: "accepted". That means we took it, not that it arrived.

StatusMeaning
acceptedWe have it.
sentHanded to WhatsApp.
deliveredOn the user's device.
readThe user opened it.
failedIt will not arrive. error says why.

Two ways to follow it:

await msg.messages.get("msg_...");   // poll

Or let us push it — see Receive webhooks. Webhooks are better: no polling, and you find out the moment it happens.

Inbound replies

There is no API to read what a user sends back. Replies arrive only as an inbound.received webhook. If you need conversation history, store the events as they arrive.

Sending number

Every message from your account goes out from one sending number.