Skip to content
AI and automation5 min read

Run a WhatsApp bot for your online store

Short answer

Use Meta's official WhatsApp Business Platform: create a Meta app with the WhatsApp product, get a phone number ID and a permanent access token, and point its webhook to an https address on your server that receives messages and replies through the Cloud API. Unofficial libraries that imitate WhatsApp Web break WhatsApp's terms and can get the number banned.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Choose your route
  2. Before you start
  3. 1. Create the Meta app
  4. 2. Write the webhook app
  5. 3. Run it on your hosting
  6. 4. Connect the webhook in Meta
  7. 5. Know the messaging rules
  8. Troubleshooting
  9. On ArabyHost

A store bot on WhatsApp answers common questions (prices, delivery, order status), sends order confirmations and hands the chat to a person when needed. There are three ways to build one, and only two are safe for a business number.

Choose your route

Route What you manage Good for
WhatsApp Business Platform (Cloud API), hosted by Meta Your own webhook app and its logic Developers who want full control
A ready automation platform Flows in a dashboard; the platform runs the connection Stores that want to start without code
Unofficial WhatsApp Web libraries Everything, plus the risk Not recommended: against WhatsApp’s terms, numbers get banned

For the second route there are several platforms; ArabyBot, a WhatsApp and Instagram automation platform from the team behind ArabyHost, is one of them. When comparing platforms, check how each connects to WhatsApp, what it costs and where your data is stored. The rest of this guide covers the first route.

Before you start

  • A Meta developer account and a Meta business portfolio (Business Manager).
  • A phone number for the bot that can receive a verification SMS or call.
  • A server that runs Node.js with an https address, for example bot.example.com.

1. Create the Meta app

  1. At Meta for Developers, create an app and add the WhatsApp product (pick the use case for connecting with customers on WhatsApp).
  2. Open WhatsApp → API Setup. You get a test number, a temporary access token, the Phone number ID and the WhatsApp Business Account ID.
  3. Add your own phone as a test recipient and send the hello_world template from that page to confirm the setup.

The temporary token expires within 24 hours. For production, create a system user in your business settings, give it access to the app and the WhatsApp account with the whatsapp_business_messaging and whatsapp_business_management permissions, and generate a permanent token.

2. Write the webhook app

The webhook does two jobs: answer Meta’s one-time verification request (GET) and receive messages (POST).

// app.js
const express = require('express');
const crypto = require('crypto');

const { WA_TOKEN, WA_PHONE_ID, WA_VERIFY_TOKEN, WA_APP_SECRET, GRAPH_VERSION } = process.env;
const app = express();
app.use(express.json({ verify: (req, res, buf) => { req.rawBody = buf; } }));

// Meta verifies the callback URL once
app.get('/webhook', (req, res) => {
  if (req.query['hub.mode'] === 'subscribe' && req.query['hub.verify_token'] === WA_VERIFY_TOKEN) {
    return res.status(200).send(req.query['hub.challenge']);
  }
  res.sendStatus(403);
});

// Incoming messages
app.post('/webhook', (req, res) => {
  const expected = 'sha256=' + crypto.createHmac('sha256', WA_APP_SECRET).update(req.rawBody).digest('hex');
  const got = req.get('x-hub-signature-256') || '';
  if (got.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected))) {
    return res.sendStatus(401);
  }
  res.sendStatus(200); // answer fast: Meta retries slow webhooks

  const msg = req.body.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
  if (msg?.type === 'text') reply(msg.from, answerFor(msg.text.body)).catch(console.error);
});

function answerFor(text) {
  if (/order|طلب/i.test(text)) return 'Send your order number and we will check it for you.';
  return 'Hello! Type "order" to track an order, or wait for a team member to reply.';
}

async function reply(to, body) {
  const r = await fetch(`https://graph.facebook.com/${GRAPH_VERSION}/${WA_PHONE_ID}/messages`, {
    method: 'POST',
    headers: { Authorization: `Bearer ${WA_TOKEN}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ messaging_product: 'whatsapp', to, type: 'text', text: { body } }),
  });
  if (!r.ok) console.error('WhatsApp API error', r.status, await r.text());
}

app.listen(process.env.PORT || 3000);

3. Run it on your hosting

Create the app in Setup Node.js App (Node.js 24, application URL bot.example.com, startup file app.js), install express in the app’s environment, and add these environment variables:

Variable Where it comes from
WA_TOKEN The system user’s permanent token
WA_PHONE_ID API Setup → Phone number ID
WA_VERIFY_TOKEN Any long random string you choose
WA_APP_SECRET App settings → Basic → App secret
GRAPH_VERSION The Graph API version shown in your app dashboard, such as v23.0

Then click Restart. Detailed steps are in Deploy a Node.js app.

4. Connect the webhook in Meta

In WhatsApp → Configuration, set the Callback URL to https://bot.example.com/webhook and the Verify token to your WA_VERIFY_TOKEN, click Verify and save, then subscribe to the messages field under Webhook fields. Send a message from your phone to the bot’s number; the reply should arrive within seconds.

5. Know the messaging rules

  • The 24-hour customer service window: after a customer messages you, you can reply freely for 24 hours. Outside that window you can only send pre-approved template messages.
  • Opt-in: message customers first only if they agreed to receive WhatsApp messages from you, for example at checkout.
  • Templates for store events: create templates such as “order confirmed” or “out for delivery” in WhatsApp Manager and send them when your store’s order webhook fires.
  • Human handoff: always offer a way to reach a person, and pause the bot while staff handle a chat.
  • Going live: add your real number, complete business verification if Meta asks for it, and add a payment method for paid messages.

Troubleshooting

  • Verify and save fails: the verify token doesn’t match, the URL isn’t https with a valid certificate, or the app doesn’t return hub.challenge as plain text.
  • Verification works but no messages arrive: the messages field isn’t subscribed, or the app wasn’t restarted with the right variables.
  • Every POST gets 401 from your app: WA_APP_SECRET is wrong, or something changed the body before the signature check.
  • Error 190: the access token expired. Use the system user’s permanent token.
  • Error 131047 (re-engagement message): more than 24 hours passed since the customer’s last message. Send a template instead.
  • Error 131030: in test mode the recipient isn’t on the allowed list. Add the number in API Setup.
  • The same message is handled twice: Meta retried because the reply was slow. Send 200 first, then do the work, and skip message IDs you’ve already seen.

On ArabyHost

The webhook runs as a Node.js app (Node.js 20 or 24) or a Python app on the AI/Developer plans, through Setup Node.js App with Phusion Passenger, and the free SSL certificate gives the callback URL the https address Meta requires. Scheduled jobs such as abandoned-cart reminders can run as cron jobs. Resources are per account, so a bot with very high message volume or long AI calls may need a larger plan. Keep tokens in the app’s environment variables, never in the code. Prefer Python? The structure is the same; Run a Telegram bot with Python shows how a Python bot runs on the same hosting.

FAQ

Should the bot use a new phone number?

A dedicated number is the simplest choice. Using a number that's already active in the WhatsApp or WhatsApp Business app means following Meta's migration or coexistence options, which have their own conditions, so read Meta's current documentation first.

Does the WhatsApp Cloud API cost money?

Meta charges for some messages, mainly template messages your business starts, at rates that depend on the country and the message category. Replies inside an open customer service window are treated differently. Check Meta's WhatsApp pricing page for the current rules.

Why not use an unofficial WhatsApp library?

Libraries that automate WhatsApp Web aren't approved by WhatsApp, can break with any app update, and can get the number banned. For a store whose customers rely on that number, the official API is the safe route.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.