The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a customizable template bot

Creating a customizable template bot involves designing a bot that can be easily adapted to serve different purposes (e.g., customer support, lead generation, FAQ assistant, etc.) with minimal changes. Below is a fully functional JavaScript-based template bot using Node.js and Express, structured to be customizable with minimal code modification.


Features:

  • Customizable greetings, questions, and responses

  • Webhook support for dynamic responses

  • Easy integration with front-end (web, apps)

  • Scalable structure


📁 File Structure

pgsql
template-bot/ ├── bot-config.js ├── index.js ├── responses/ │ ├── defaultResponses.js │ └── customResponses.js ├── utils/ │ └── responseHandler.js ├── package.json

📦 package.json

json
{ "name": "template-bot", "version": "1.0.0", "main": "index.js", "scripts": { "start": "node index.js" }, "dependencies": { "express": "^4.18.2", "body-parser": "^1.20.2" } }

📄 bot-config.js

js
module.exports = { botName: "FlexBot", greeting: "Hello! I'm FlexBot. How can I help you today?", fallbackMessage: "Sorry, I didn't understand that. Can you rephrase?", defaultFlow: true, customFlowFile: "./responses/customResponses" };

📄 index.js

js
const express = require("express"); const bodyParser = require("body-parser"); const config = require("./bot-config"); const defaultResponses = require("./responses/defaultResponses"); const customResponses = require(config.customFlowFile); const handleResponse = require("./utils/responseHandler"); const app = express(); app.use(bodyParser.json()); app.post("/webhook", (req, res) => { const userMessage = req.body.message?.toLowerCase() || ""; const response = handleResponse(userMessage, config.defaultFlow ? defaultResponses : customResponses, config.fallbackMessage); res.json({ bot: config.botName, response }); }); app.get("/", (req, res) => { res.send(config.greeting); }); app.listen(3000, () => { console.log(`${config.botName} is running on http://localhost:3000`); });

📄 responses/defaultResponses.js

js
module.exports = { "hi": "Hey there! How can I assist you?", "hello": "Hello! Need any help today?", "help": "I can help you with general inquiries, account info, or support.", "bye": "Goodbye! Feel free to return if you need more help." };

📄 responses/customResponses.js

js
module.exports = { "price": "Our products range from $19.99 to $99.99. Do you want to see a full catalog?", "support": "Please describe the issue you're facing. A human agent can also be contacted at support@example.com.", "order status": "To check your order status, provide your order ID or email used during purchase.", "return": "We have a 30-day return policy. You can initiate a return from your account dashboard." };

📄 utils/responseHandler.js

js
function handleResponse(message, responses, fallback) { for (let key in responses) { if (message.includes(key)) { return responses[key]; } } return fallback; } module.exports = handleResponse;

🛠 How to Customize

  1. Edit bot-config.js to change the bot name, greeting, and toggle between default/custom responses.

  2. Modify or add new entries in customResponses.js for more specific conversations.

  3. Extend logic in responseHandler.js for more advanced NLP or AI integration.


🧪 Example API Call

POST to /webhook

json
{ "message": "What's your return policy?" }

Response

json
{ "bot": "FlexBot", "response": "We have a 30-day return policy. You can initiate a return from your account dashboard." }

This template bot is modular, scalable, and ready to be deployed or extended with NLP services like Dialogflow, OpenAI API, or Rasa. Let me know if you want a frontend UI or a version in Python.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About