How to Build a Business Chatbot With an AI API
By Darus S Alfatah · 2025-08-09 · Tutorial · 12 menit
Author note: A useful chatbot always has a path to a human. Without it, one wrong answer can lose a customer.
Start From Questions, Not Technology
Most failed chatbot projects start with a model and look for a use case. Successful ones start with a list of questions customers actually ask. Collect the last one hundred messages from WhatsApp, Instagram, and marketplace chat, then group them into themes.
You will usually find that twenty questions account for eighty percent of volume. That small set is your first scope.
Answering From Real Data
A chatbot without product data will invent answers. The practical approach is a small retrieval layer: store the catalogue in a table, embed each entry, then retrieve the five most relevant before calling the model.
const rows = await db.query(
'SELECT name, price, stock FROM products ORDER BY embedding <=> $1 LIMIT 5',
[questionEmbedding]
);
const context = rows.map(r => r.name + ' - ' + r.price + ' - stock ' + r.stock).join('
');
Escalation Rules
Define triggers: the customer mentions a complaint, refund, or legal issue; the bot fails twice in a row; or the user types “agent”. When triggered, stop the automated flow and create a ticket. This prevents frustration that turns into bad reviews.
Instruction Structure
Role: customer service assistant for [shop].
Language: Indonesian, friendly but concise, max 3 sentences.
Allowed: catalogue, shipping, hours, return policy.
Never: promise delivery dates, negotiate price, discuss competitors.
If unsure: say so and offer human help.
Keep instructions short enough to survive every request without exploding context cost.
Measuring Success
Track three numbers: share of conversations resolved without a human, time to first reply, and satisfaction after the conversation. If resolution rises but satisfaction falls, the bot is answering more but helping less.
Checklist Before Launch
- Catalogue and policies are current.
- Escalation path tested with a real agent.
- Bot identifies itself as AI.
- Prompt cost measured per conversation.
- Weekly review of failed conversations scheduled.
Iterating Without Breaking Things
Keep twenty real customer questions as a regression test. After every prompt or data change, run them and compare. Most “improvements” that break a chatbot are invisible without this habit.
Conclusion
A useful chatbot is mostly good data and clear boundaries. The model matters less than whether the answers are accurate and whether people can reach a human when they need one.
Designing the Conversation
Customers on WhatsApp write short messages, often without context: "how much?", "still available?", or just a sticker. The bot must remember what it asked a moment ago, otherwise every exchange restarts from zero. Store a compact state per phone number: which menu the customer is in, what information is missing, and whether a human has joined.
When the customer switches topic, detect the switch and reset the state instead of continuing an old assumption. When a human agent takes over, disable automatic replies for that conversation so the customer does not receive two competing answers. These details matter more than model choice; a brilliant model with no conversation state feels broken, while a modest model with good state handling feels competent.
Also design the first message carefully. It should state what the bot can help with, in one short sentence, and offer the two or three most common actions as quick choices. Customers who see their question listed will tap it; customers who see a vague greeting will type something unpredictable.
Example: an online store FAQ: The bot answers opening hours, return policy, and shipping status. If a customer mentions words like cancel or complaint, route straight to a human agent.
Frequently Asked Questions
Can beginners follow this tutorial?
Yes. The steps are explained in order with code examples, suitable for beginners and experienced developers alike.
Is BankAI’s endpoint compatible with the library I already use?
Yes, BankAI is 100% OpenAI-compatible, so libraries such as the OpenAI SDK and LangChain work without code changes beyond the Base URL and API key.
Where do I get an API key to follow this tutorial?
You get the API key (and Secret Token) after registering and completing payment in the BankAI dashboard.