Documentation

Build with e-bot

Everything store owners and developers need to launch an AI-powered Messenger storefront — from your first product upload to the webhook payload.

Getting Started

What is e-bot?

e-botis a chatbot backend that plugs an e-commerce store's social media pages into an AI assistant. When a customer messages your Facebook page (Instagram support is on the way), e-bot answers product, pricing, policy, and delivery questions automatically — and can take an order end-to-end inside Messenger.

It runs on FastAPI, PostgreSQL with pgvector, Redis, Celery, and OpenAI's tool-use API. Visual search is powered by DINOv2 — when a customer sends a product photo, the bot finds the matching item by image similarity, not by keyword guesswork.

How it works

Every customer message follows the same five-step pipeline:

  1. 1

    Message arrives

    A customer sends text, an image, or both to your Facebook page. Facebook forwards the event to e-bot's webhook.

    0
  2. 2

    Background queue

    The webhook hands the event to a Celery worker so the request returns instantly — no Facebook timeouts.

    1
  3. 3

    Search or reason

    If the customer sent an image, DINOv2 finds the matching product via pgvector similarity search. If it's text, the LLM decides which tool to call (search_products, list_products, get_delivery_zones, place_order, …).

    2
  4. 4

    Compose the reply

    The LLM receives the tool result plus the conversation history and writes a reply in the customer's own language.

    3
  5. 5

    Send back

    e-bot sends the reply through the Messenger Send API. The whole loop usually takes under three seconds.

    4

Set up your store

Onboarding takes about 15 minutes if your product catalog is ready. Each step below corresponds to a screen in the e-bot dashboard.

1

Create a store account

From the dashboard, click ‘New Store’ and give your store a name. You'll get a store ID — most API endpoints are scoped to it.

2

Connect your Facebook Page

You'll need a Page Access Token from Meta Business Suite. Paste it into the Connections screen along with your Page ID. The token is encrypted before being stored.

3

Upload your product catalog

Add products one at a time or upload up to 100 at once via Bulk Import. Each product needs a title, price, stock count, sizes, and at least one publicly-accessible image URL. Optional fields: description, discount, offer text. After upload, DINOv2 generates a visual embedding in the background.

4

Add delivery zones

Tell the bot what areas you deliver to and what each one costs (e.g. Inside Dhaka — 60 BDT, Outside Dhaka — 120 BDT). The bot uses these zones during the Messenger order flow.

5

Add physical store locations

If you have brick-and-mortar branches, add their address, phone, and opening hours. Customers asking ‘where is your shop?’ get an accurate answer.

6

Write a return / exchange policy

Plain text in the store settings. The bot quotes it back verbatim when customers ask about returns.

7

Go live

Subscribe your Page to the webhook (the dashboard generates the URL and verify token). Send a test message to confirm the round-trip works, then let real customers in.

What customers can do

  • Image search — send a photo, get the matching product with price, sizes, and stock.
  • Text search— ask “black winter t-shirt er price koto?” and get a hit from the catalog.
  • Browse — ask to see all products or filter by size or price range.
  • Store info — opening hours, branch locations, return policy.
  • Delivery — ask about zones and charges before ordering.
  • Place an order — a four-step conversational flow inside Messenger: confirm intent → address → delivery zone → final confirmation.
  • Follow-up— “XL ache?” or “return kora jabe?” after a product is identified are answered from a 5-minute Redis cache, no repeat database hit.

Languages

e-bot detects whether the customer wrote in English, Bangla (বাংলা), or Banglish(Bengali meaning written in English letters — “ei ta koto?”).

Replies are always in the customer's language. The bot never switches unless the customer does. This is enforced in the system prompt — you don't need to configure anything.

FAQ

How much does the OpenAI API cost per conversation?

Every LLM call is logged per store in the token_usage table. You can monitor cumulative cost from the dashboard. A typical product question uses 1–3 tool calls, around 1,500–3,000 tokens total. Image-search-only flows skip the LLM entirely.

What happens if my Facebook Page Access Token expires?

Messenger calls will start failing with a 401. The bot will keep accepting webhooks but won't be able to reply. Reconnect the page from the Connections screen to refresh the token.

Can I edit a product after it's uploaded?

Yes — from the Products screen. If you change the images, the visual embedding is regenerated in the background.

How many products can I have?

There is no hard cap. pgvector with the HNSW index keeps similarity search fast into the tens of thousands of items.

Does the bot place orders without confirmation?

No. The order flow always shows the customer a full summary (items, subtotal, delivery charge, total) and waits for an explicit confirmation before calling place_order.

Can the bot message a customer first?

Yes, via the proactive messaging endpoint. Outside Facebook's 24-hour window you must include a valid message_tag (POST_PURCHASE_UPDATE, CONFIRMED_EVENT_UPDATE, or HUMAN_AGENT).

Where is data stored?

Products, orders, and conversations are in PostgreSQL. Redis holds the 5-minute product context cache and Celery task queue. Facebook access tokens are encrypted at rest.

Does Instagram work?

Not yet — it's on the roadmap. Today only Facebook Messenger is supported.

API Reference

Overview

The HTTP API is a thin layer over the same database the bot reads. Everything is JSON. Authentication is environment-specific — in self-hosted deployments the API is reached on a private network or behind your own auth gateway.

Base URL

text
http://localhost:8000/api/v1

Response envelope

Every endpoint returns this shape:

json
{
  "success": true,
  "data": { /* endpoint-specific payload */ },
  "error": null
}

On failure, success is false, data is null, and error contains a message string.

Stores

Create a store

POST/stores
Request
{
  "name": "My Fashion Store",
  "owner_id": "user_123"
}
Response
{
  "data": {
    "id": 1,
    "name": "My Fashion Store",
    "owner_id": "user_123",
    "description": null,
    "return_policy": null,
    "created_at": "2026-04-06T10:00:00Z",
    "updated_at": null
  }
}

Get a store

GET/stores/{store_id}

Update a store

PATCH/stores/{store_id}

All fields are optional.

Request
{
  "name": "Updated Store Name",
  "description": "We sell premium fashion for all seasons.",
  "return_policy": "Returns accepted within 7 days with original tag."
}

Facebook Pages

Connect a page

POST/stores/{store_id}/connect-page
Request
{
  "page_id": "123456789",
  "page_name": "My Fashion Store",
  "page_access_token": "EAAxxxxxx..."
}

The page_access_token comes from the Facebook Graph API. The token is encrypted before persisting.

List connected pages

GET/stores/{store_id}/pages

Delivery Zones

Add a zone

POST/stores/{store_id}/delivery-zones
Request
{
  "zone_name": "Inside Dhaka",
  "charge": 60.00,
  "description": "All areas within Dhaka city"
}

List, update, delete

GET/stores/{store_id}/delivery-zones
PATCH/stores/{store_id}/delivery-zones/{zone_id}
DELETE/stores/{store_id}/delivery-zones/{zone_id}

Store Locations

Add a location

POST/stores/{store_id}/locations
Request
{
  "location_name": "Dhanmondi Branch",
  "address": "House 10, Road 4, Dhanmondi, Dhaka",
  "phone": "01700000000",
  "opening_hours": "Sat-Thu: 10am-9pm"
}

List, update, delete

GET/stores/{store_id}/locations
PATCH/stores/{store_id}/locations/{location_id}
DELETE/stores/{store_id}/locations/{location_id}

Products

Add one product

POST/products
Request
{
  "title": "Black Winter T-Shirt",
  "descriptions": "Premium quality cotton winter t-shirt.",
  "price": 850.00,
  "currency": "BDT",
  "stock": 50,
  "sizes": ["S", "M", "L", "XL"],
  "images": [
    "https://cdn.example.com/black-tshirt-front.jpg",
    "https://cdn.example.com/black-tshirt-back.jpg"
  ],
  "discount": 10.00,
  "offer": "10% off this week",
  "store_id": 1
}

After creation, visual embedding generation runs in the background. Image URLs must be publicly accessible.

Bulk import (max 100 per call)

POST/products/bulk
Request
{
  "products": [
    {
      "title": "Red Hoodie",
      "price": 1200.00,
      "currency": "BDT",
      "stock": 30,
      "sizes": ["M", "L", "XL"],
      "images": ["https://cdn.example.com/red-hoodie.jpg"],
      "store_id": 1
    }
  ]
}

Get a product

GET/products/{product_id}

Orders

List orders

GET/stores/{store_id}/orders

Filter with ?status= where status is one of pending, confirmed, cancelled, delivered.

Response
{
  "data": [
    {
      "id": 1,
      "store_id": 1,
      "messenger_user_id": 5,
      "conversation_id": 2,
      "delivery_address": "House 10, Road 4, Dhanmondi",
      "delivery_zone_name": "Inside Dhaka",
      "delivery_charge": "60.00",
      "subtotal": "850.00",
      "total": "910.00",
      "currency": "BDT",
      "status": "pending",
      "created_at": "2026-04-06T10:00:00Z",
      "items": [
        {
          "id": 1,
          "product_id": 42,
          "product_name": "Black Winter T-Shirt",
          "size": "L",
          "quantity": 1,
          "unit_price": "850.00",
          "currency": "BDT",
          "line_total": "850.00"
        }
      ]
    }
  ]
}

Get one order

GET/stores/{store_id}/orders/{order_id}

Proactive Messaging

Send a message to a customer outside of an in-progress conversation — e.g. an order confirmation or a delivery update.

POST/stores/{store_id}/send-message
Request
{
  "page_id": "123456789",
  "recipient_id": "PSID_of_the_customer",
  "message": "Your order has been confirmed! We'll deliver within 2-3 days.",
  "message_tag": "POST_PURCHASE_UPDATE"
}

message_tag is required if the customer last interacted more than 24 hours ago. Valid values: POST_PURCHASE_UPDATE, CONFIRMED_EVENT_UPDATE, HUMAN_AGENT. Omit it if the customer messaged within the last 24 hours.

Webhook

Facebook calls these endpoints — you generally don't hit them directly. The verification endpoint is used once during Page subscription; the POST endpoint receives every Messenger event going forward.

GET/webhook
POST/webhook

Health

GET/health

Returns 200 with { "status": "ok" } when the API is reachable. Use this as your container health probe.