← Back to builds

Pagewala: an AI sales agent for Facebook Page sellers

How I built an AI agent that answers customer questions and captures orders through Messenger for small sellers in Bangladesh, without letting it invent a single price.

Role: Solo founder & engineer: product, design, and full-stack build

Next.jsTypeScriptAI AgentsMeta Graph API
Visit live site →
Pagewala screenshot

The problem#

Small businesses across Bangladesh sell almost entirely through Facebook Pages. Every sale starts as a Messenger conversation: "price?", "available?", "delivery kobe hobe?", often with a product photo or a link to a post. Sellers answer the same questions hundreds of times a day, take orders by hand in chat, and lose sales whenever they're slow, offline, or overwhelmed.

Off-the-shelf chatbots don't fit. They answer questions but don't sell, they don't understand Banglish, and they don't know the seller's actual catalog.

What Pagewala does#

Pagewala connects to a seller's Facebook Page and acts as an always-on salesperson in Messenger:

  • Answers product questions in Bangla, English, or Banglish, matching whatever the customer writes.
  • Understands photos and post links. A customer can send a screenshot or paste a post URL and get the right product back.
  • Actually sells. It nudges browsers toward a decision, suggests one complementary item, and handles "too expensive" without just repeating the price.
  • Captures orders by collecting name, phone, address, and payment method one question at a time, then confirming a full recap before anything is recorded.
  • Turns comments into conversations. When someone comments "price?" under a post, Pagewala replies privately in Messenger with that post's product already in context.
  • Hands off to a human when it isn't sure, when the customer is upset, or when a seller-defined trigger word appears, and then stays silent until the seller turns it back on.

Sellers get a dashboard with live conversations, orders (with export), analytics, and per-page agent settings. The catalog can be entered by hand, synced from Facebook posts, or imported from a CSV or Excel file.

How it works#

Built with Next.js 16, Postgres on Neon through Drizzle, and Gemini 2.0 Flash, called over plain HTTP behind a small provider interface (Ollama is a drop-in alternative).

  1. Webhook in, 200 out. Facebook's webhook is verified with an HMAC-SHA256 signature and answered immediately. The agent runs in the background with Next's after(), and every message is de-duplicated by its Facebook message ID, because Facebook retries for up to 24 hours.
  2. An input pipeline decides what the customer sent: button tap, post link, photo, voice, or text. A post link is matched exactly against synced posts first, then by the post's text through the Graph API.
  3. Retrieval without a vector database. Seller catalogs are small (20 to 200 products), so the whole catalog is loaded and keyword-matched in memory. The products being discussed are remembered on the conversation, so a follow-up like "XL size ache?" still knows which shirt it means.
  4. One model call per message. Photos are passed inline with up to 100 candidate products rather than through a separate vision call, which halves the cost per image.
  5. Two tools, nothing else: place_order and escalate.

The dashboard updates live using Postgres LISTEN/NOTIFY streamed over server-sent events, so there's no Redis or Pusher to run.

The hard parts#

Never trusting the model with money. The model is told to use only listed products, but the server doesn't rely on that. place_order ignores any price the model sends and looks up each item from the database. It validates quantities and decrements stock atomically inside a transaction, so if any item runs out mid-order, the whole order rolls back.

Stopping the double order. Customers end with "ok, thanks!", and the model would sometimes place the same order again. Three layers fix it:

  • the prompt receives an [ORDER STATUS] block describing the order already placed;
  • earlier turns in the history are annotated with whether place_order actually succeeded;
  • the server rejects any identical set of items in the same conversation within 15 minutes.

Selling, not just answering. A [SALES BEHAVIOR] section in the prompt makes the agent act like an experienced Bangladeshi seller: invite a decision after a few questions, suggest at most one extra item, and mention low stock only when it's true.

Spending AI calls only where they matter. Comments are high volume, so buying intent is detected with a Bangla, Banglish, and English keyword list, with no model call. Trigger words escalate before the model is called. The first AI call happens only when a customer actually replies in Messenger.

Facebook's 24-hour rule. A page can only reply within 24 hours of the customer's last message. A cron job marks expired conversations in the dashboard, and any new message from the customer reopens them automatically.

Where it stands#

Pagewala is live at pagewala.com. A seller can sign up for free, connect a Facebook Page, add a catalog, and have the agent answering Messenger in under 10 minutes, with no credit card.

I built it solo, from the first commit in April 2026 to a working product with a seller dashboard, order management, analytics, comment automation, and a platform admin panel by August.

What I learned#

Building it was the easy part.

Getting an agent to hold a good sales conversation in Bangla and Banglish came together faster than I expected. In a demo, a model that gets things right almost every time looks finished.

Production is different. Once real customers, real sellers, and real money are involved, "almost every time" isn't good enough. The rare miss is an order at the wrong price, the same order placed twice, or the last item sold to two people. Each of those lands on a small business that has to pack, ship, refund, or apologize for it.

That's why most of the work in this case study isn't about the conversation at all. It's the server-side price lookup, the atomic stock update, and the duplicate-order guard. Building is easy. Production hits harder, especially when it touches money, so I now design for the failure cases from the first line.

What's next#

WhatsApp alerts for new orders and escalations are designed but not wired up yet; today sellers see them in the dashboard. Background work will also move from after() to a durable queue, so a slow model call can never be lost.