How to Set Up WhatsApp API Auto Replies for Offline Hours

If you run a business in Pakistan or India, you know that customers do not wait for business hours. They will message your WhatsApp number at 2:00 AM expecting an immediate response. If you are using the free WhatsApp Business App, you have probably tried the built-in "Away message" feature.
But the free app has a major flaw: it requires your physical phone to be turned on, connected to the internet, and unaffected by local power cuts or internet outages. In cities like Karachi, Lahore, or Mumbai, load shedding or fiber cuts can take your phone offline, killing your automated responses.
The WhatsApp Cloud API solves this because it runs on Meta's cloud servers, which are never offline. However, the API does not have a simple "Away message" toggle switch in the Meta Business Suite. You have to build the logic yourself or use a tool to do it.
This guide explains how to set up offline auto-replies on the WhatsApp API, the actual costs involved, the technical steps to build it, and the traps that will waste your money if you get the logic wrong.
The Real Costs and Limits of API Auto-Replies
Before writing code or signing up for software, you must understand how Meta charges for these automated messages. Every message you send via the API has a cost attached to it, governed by Meta's conversation-based pricing model.
Meta charges for 24-hour conversation windows. The cost depends on who starts the conversation and the category of the message. There are four categories: Marketing, Utility, Authentication, and Service.
| Conversation Category | Who Initiates It | Pricing Principle |
|---|---|---|
| Service Conversation | User messages you first, you reply with a free-form message. | Billed per 24-hour window once your reply is delivered. |
| Utility Conversation | Business sends a structured template (e.g., order updates, receipts). | Billed per 24-hour window. |
| Marketing Conversation | Business sends promotional templates, offers, or greetings. | Highest cost tier, billed per 24-hour window. |
When a customer messages you during your offline hours, they initiate the interaction. If your system automatically replies with an "out of office" text, this starts a Service Conversation.
In India, a service conversation costs approximately INR 0.29. In Pakistan, Meta bills in USD, costing about $0.0147 per service conversation. You can check the exact current rates for your specific country on the Meta Developer Pricing Sheet.
If the user messages you, and your auto-reply goes out, you pay for that 24-hour window. If they reply again within those 24 hours, you do not pay extra. But if they message you on Friday night, your bot replies, and then they message you again on Sunday night, you will be billed for two separate conversation windows.
There is also a rate limit to keep in mind. By default, new WhatsApp API accounts are limited to 80 messages per second (MPS) across both incoming and outgoing traffic. For most mid-sized businesses, this is more than enough. If you expect thousands of concurrent midnight messages, you must request a limit increase from Meta.
How to Build the Offline Auto-Reply Logic
Since the Cloud API does not know your office hours, your backend server or your middleware software must handle the logic. Here is how the system should process an incoming message when your team is asleep.
Step 1: Set Up Your Webhook
When a customer sends a message, Meta sends an HTTP POST payload (a webhook) to your server. Your server must listen to this payload, parse the incoming message, and extract the sender's phone number and the message timestamp.
Here is an example of what the incoming payload looks like when a customer messages you:
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "109983325012345",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "923001234567",
"phone_number_id": "105543210987654"
},
"contacts": [
{
"profile": {
"name": "Zubair Khan"
},
"wa_id": "923009876543"
}
],
"messages": [
{
"from": "923009876543",
"id": "wamid.HBgLOTIzMDA5ODc2NTQzFQIAERgSQzRDNTA1N0U2N0REMDkxODNFAA==",
"timestamp": "1715623200",
"text": {
"body": "Are you open right now?"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
Step 2: Evaluate the Timestamp Against Business Hours
Your server needs a configuration file or a database table defining your working hours. For example, your hours might be Monday to Friday, 9:00 AM to 6:00 PM, in your local timezone (e.g., PKT or IST).
Convert the incoming Unix timestamp (1715623200 in the payload above) into your local time. If the current time falls outside your defined working hours, or if the current day is a weekend or public holiday, trigger the offline workflow.
Step 3: Check for the "Loop Trap"
Never send an auto-reply instantly without checking your database first. If you skip this step, you risk falling into an infinite loop.
For example, if a customer has an automated out-of-office reply on their own WhatsApp number, or if they send multiple messages in a row ("Hello", "Are you there?", "Please reply"), your server will send an offline reply for every single incoming message. This will deplete your Meta credit balance within minutes and get your number flagged for spam.
To prevent this, store the sender's phone number in a temporary cache (like Redis) or your database with a 12-hour or 24-hour expiration. Before sending the offline reply, check if you have already sent them an offline message within that time frame. If yes, ignore the incoming message and do not reply.
Step 4: Send the Response Payload
If the user is messaging during offline hours and has not received an offline message recently, send a POST request to Meta's message endpoint:
https://graph.facebook.com/v20.0/{your-phone-number-id}/messages
Use this JSON body to send a standard text message. Because the user messaged you first, the 24-hour customer service window is open, meaning you can send a standard text message instead of a pre-approved template.
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "923009876543",
"type": "text",
"text": {
"preview_url": false,
"body": "Thank you for reaching out! Our office is currently closed. Our team will get back to you when we open at 9:00 AM tomorrow. If this is an urgent matter, please visit our website help desk."
}
}
Remember to include your Bearer Token in the authorization header of this request.
The No-Code Alternative: Using a Middleware Platform
If you do not have a developer on hand to write custom webhook listeners, manage server uptime, or handle Redis caching, you can use a tool to bridge the gap.
We built WA Link to solve this specific problem. It connects directly to your WhatsApp Cloud API account and lets you set up routing rules, working hours, and auto-replies without writing code.
However, you should know what WA Link cannot do. It cannot bypass Meta's platform fees. You still pay Meta directly for the conversation windows. It also cannot send messages to users who have blocked your number or opted out of your communications. It simply manages the routing logic and the scheduling on your behalf so you do not have to host your own server.
When an Offline Auto-Reply is the Wrong Choice
Automated out-of-office replies are not always the best solution. In some scenarios, they can damage your customer relationships or cost you unnecessary money.
1. High-Frequency Transactional Alerts
If your WhatsApp API number is primarily used for sending automated OTPs, password resets, or shipping notifications, do not set up a global offline auto-reply.
If a customer requests an OTP at midnight, they do not want an auto-reply saying "We are closed." They want their OTP. If your webhook triggers an offline message to every incoming text on a transactional number, you will confuse users and pay for useless service conversations.
2. The "Dead End" Experience
Do not send a generic "We are offline" message without giving the user a clear next step. If your auto-reply simply says, "We are closed, goodbye," the user feels ignored.
Instead, provide alternative resources. Link to your documentation, your shipping tracking page, or a self-service portal. If you cannot provide a link, tell them exactly when they will receive a human response.
3. Ignoring Existing Open Tickets
If a customer has an active support ticket that your team is resolving, and they send an update outside of hours, an automated "We are closed" message can feel robotic and annoying.
If you have a CRM integrated with your WhatsApp API, configure your webhook to check the status of the customer's ticket. If they have an active ticket assigned to an agent, suppress the generic offline reply and let the agent handle it when they log back in.
Best Practices for Writing Your Offline Messages
If you decide to set up an auto-reply, keep your copy clear and direct. Avoid corporate jargon and set realistic expectations.
- Be honest about response times: Do not say "We will reply shortly" if your team does not log on until Monday morning. Say "We will reply by 10:00 AM on Monday."
- Keep it short: Users read WhatsApp messages on their phones. A wall of text will be ignored. Keep your message under 80 words.
- Use formatting: Use bold text for key details like working hours or emergency contact numbers. Use bullet points if you are listing resources.
- Do not sell: Your customer is messaging you with a query. An offline auto-reply is not the place to pitch a new product or share a discount code unless it is directly relevant to their issue.
Frequently Asked Questions
Do I need to keep my phone connected to the internet for API auto-replies to work?
No. This is the main benefit of the WhatsApp API over the standard WhatsApp Business App. The API is hosted on cloud servers. Even if your office has a power outage, your physical phone is turned off, or your team has no internet connection, the auto-replies will still send instantly.
Can I use media like images or PDFs in my offline reply?
Yes. Because the customer initiated the conversation, you can reply with any message type supported by the API during the 24-hour window. This includes images, PDFs, audio files, or interactive buttons. However, keep in mind that media messages can take slightly longer to load on slow mobile connections.
How do I handle public holidays?
If you are coding your own solution, you must maintain a list of holiday dates in your database. Your webhook logic should check both the weekly working hours and the holiday list before deciding to send the offline reply. If you use a platform like WA Link, you can configure holiday schedules directly within the user interface.
What happens if a user messages me multiple times while we are offline?
If your system is built correctly, the user should only receive one offline reply per 24-hour period. If your server does not have duplicate check logic, it will reply to every single message, which will annoy your customers and cost you money in conversation fees.
Can I set up different offline replies for different departments?
Yes, if you use an interactive list or button message first. For example, when a user messages you, you can reply with a menu: "Press 1 for Sales, 2 for Support." If they choose Sales, and your sales team is offline, you can trigger the sales-specific offline message. If they choose Support, and you have a 24/7 support team, they can bypass the offline message entirely.