“AI Chatbot SaaS Platform” Complete Documentation v1.0
“AI Chatbot SaaS Platform”
Thank you for choosing our AI Chatbot SaaS Platform! This comprehensive
documentation will guide you through installation, configuration, and usage. If you have any
questions, please contact our support team.
Table of Contents
- Installation & Setup
- Environment Variables & API Keys
- Admin Settings Configuration
- Build & Deployment Guide
- Creating Your First Chatbot
- Widget Integration
- Website Usage Guide
- Key Features
- Troubleshooting
- Support
A) Installation & Setup - top
🚀 Quick Start Guide
Follow these steps to get started:
Prerequisites
- Node.js 18+ - Download here
- PostgreSQL - Database server (or use Supabase cloud)
- npm - Comes with Node.js
Step 1: Install Dependencies
Install all required npm packages:
npm install
Note: This may take a few minutes depending on your internet connection. Make sure you
have a stable connection.
Step 2: Environment Variables Setup
Create a .env file in the root directory. Copy from .env.example if available:
cp .env.example .env
Or create manually. See Section B for detailed API key setup.
Step 3: Database Setup
Generate Prisma client and push schema to database:
npm run db:generate
npm run db:push
Step 4: Create Admin Account
Create your first admin user:
npm run create-admin
Or with custom credentials:
npm run create-admin admin@example.com YourPassword123 "Admin Name"
Step 5: Start the Application
Development Mode:
npm run dev
Production Mode:
npm run build
npm start
✅ Success! Your application should now be running at http://localhost:3000
B) Environment Variables & API Keys - top
🔑 Required API Keys
You need to configure these in your .env file:
1. Database Configuration (DATABASE_URL)
Option A: Local PostgreSQL
- Install PostgreSQL from postgresql.org
- Create a database:
psql -U postgres
CREATE DATABASE chatflow;
\q
- Add to
.env:
DATABASE_URL="postgresql://postgres:YourPassword@localhost:5432/chatflow"
Option B: Supabase (Free Cloud Database - Recommended)
- Go to supabase.com and create a free account
- Create a new project
- Go to Settings → Database → Connection String
- Copy the URI and paste into
.env
2. AI API Keys
🌟 Recommended: Google Gemini API
Why Gemini? Gemini offers excellent performance, competitive pricing, and is recommended
for this platform.
Getting Gemini API Key:
- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Select or create a Google Cloud project
- Copy the API key (starts with
AIza...)
- Add to
.env:
GEMINI_API_KEY="AIzaSy..."
Alternative: OpenAI API Key
- Go to platform.openai.com and create an account
- Navigate to API Keys
- Click "Create new secret key"
- Copy the key (shown ONLY ONCE - save it!)
- Add billing information (minimum $5 credit)
- Add to
.env:
OPENAI_API_KEY="sk-proj-..."
🚀 OpenRouter Embeddings
If you want to use Anthropic Claude, Meta Llama, Mistral, or hundreds of other models instead of OpenAI,
you can use OpenRouter as a full replacement, including for Knowledge Base Embeddings!
Setting up OpenRouter for Everything:
- Go to OpenRouter.ai and create an account
- Navigate to Keys and click Create Key
- Add credits to your account if needed
- Update your
.env file to override the OpenAI Base URL and Key:
OPENAI_API_KEY="sk-or-v1-your-openrouter-key"
OPENAI_BASE_URL="https://openrouter.ai/api/v1"
- Now you can enter any OpenRouter Model ID (e.g.,
anthropic/claude-3.5-sonnet) in your
Dashboard for chat responses!
🔥 Using OpenRouter for RAG & Knowledge Base (Embeddings)
When users upload PDF or Text files to train the AI (Knowledge Base), the system needs to convert text
into
vectors (Embeddings). OpenRouter natively supports embedding models and serves as a direct proxy!
By just setting the OPENAI_BASE_URL to OpenRouter as shown above, all embedding requests
will automatically be routed through OpenRouter seamlessly without requiring any separate real OpenAI
key.
3. JWT Secret Key
Generate a secure random key (minimum 32 characters):
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Add to .env:
JWT_SECRET="your-generated-secret-key-here-minimum-32-characters"
4. Application URL
NEXT_PUBLIC_APP_URL="http://localhost:3000"
For production, change to your domain:
NEXT_PUBLIC_APP_URL="https://yourdomain.com"
5. Stripe Configuration (Optional - for payments)
- Go to Stripe Dashboard and create an account
- Navigate to Developers → API Keys
- Copy Secret key (starts with
sk_test_ for test mode)
- Copy Publishable key (starts with
pk_test_)
- Add to
.env:
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
- For webhooks, install Stripe CLI and run:
stripe listen --forward-to localhost:3000/api/stripe/webhook
- Copy the webhook secret and add:
STRIPE_WEBHOOK_SECRET="whsec_..."
6. PayPal Configuration (Optional - for payments)
- Go to the PayPal Developer Dashboard
- Navigate to Apps & Credentials
- Create a new app or open an existing one
- Copy your Client ID and Secret Key
- Add to
.env:
NEXT_PUBLIC_PAYPAL_CLIENT_ID="your_client_id_here"
PAYPAL_CLIENT_SECRET="your_secret_key_here"
PAYPAL_MODE="sandbox" # Use "live" for production
Complete .env File Example
# Database
DATABASE_URL="postgresql://postgres:password@localhost:5432/chatflow"
# JWT Secret (generate randomly)
JWT_SECRET="your-32-character-secret-key-here"
# AI API Keys (Gemini recommended)
GEMINI_API_KEY="AIzaSy..."
OPENAI_API_KEY="sk-proj-..." # Optional
# Application URL
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Stripe (Optional)
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."
# PayPal (Optional)
NEXT_PUBLIC_PAYPAL_CLIENT_ID="your_client_id"
PAYPAL_CLIENT_SECRET="your_secret"
PAYPAL_MODE="sandbox"
C) Admin Settings Configuration - top
⚙️ Important Admin Settings
After logging in as admin, configure these essential settings:
Step 1: Access Admin Panel
- Go to
http://localhost:3000/login
- Login with your admin credentials
- You'll be redirected to
/admin dashboard
Step 2: Configure Domain Settings
- Go to Admin → Settings (or
/admin/settings)
- Find "App Base URL" or "Domain Settings" section
- Update the domain URL:
- Development:
http://localhost:3000
- Production:
https://yourdomain.com
- Click "Save"
Important: The domain URL is used for widget integration. Make sure it matches your
actual domain in production!
Step 3: Configure Stripe Settings
- In Admin Settings, find "Payment Settings" or "Stripe Configuration"
- Enter your Stripe keys:
- Stripe Secret Key: From your
.env file
- Stripe Publishable Key: From your
.env file
- Webhook Secret: From Stripe CLI or dashboard
- Click "Save" to save Stripe keys
Step 3.5: Configure Stripe Price IDs (Important!)
⚠️ Important: You must configure Stripe Price IDs for subscription plans to work
correctly!
- Go to Admin → Settings → Subscriptions tab (or navigate to
/admin/settings
and click on "Subscriptions" tab)
- You'll see subscription plan settings for STARTER, PROFESSIONAL, and ENTERPRISE plans
- For each subscription plan, you need to set the Stripe Price ID in the "Stripe Price
ID" field:
- How to get Stripe Price ID:
- Go to Stripe Dashboard → Products
- Create a product for each plan (or use existing ones)
- Add a price to each product
- Copy the Price ID (starts with
price_)
- Example:
price_1ABC123def456GHI789
- Enter Price IDs:
- Free Plan Price ID: Usually leave empty or set to
null
- Basic Plan Price ID: Enter your Stripe Price ID (e.g.,
price_1ABC123...)
- Pro Plan Price ID: Enter your Stripe Price ID
- Enterprise Plan Price ID: Enter your Stripe Price ID
- Make sure each Price ID matches the correct plan and billing cycle (monthly/yearly)
- Click "Save" or "Update" for each plan
💡 Tip: Stripe Price IDs are unique identifiers for each pricing tier. They link your
subscription plans to Stripe's payment system. Without correct Price IDs, users won't be able to
subscribe to paid plans.
Example Stripe Price IDs:
Free Plan: (empty or null)
Basic Plan: price_1ABC123def456GHI789
Pro Plan: price_1XYZ789ghi012JKL345
Enterprise Plan: price_1MNO456pqr789STU012
Step 3.6: Configure PayPal Settings
- In Admin Settings, find the "Payment Settings" section
- Toggle Enable PayPal if you wish to offer it alongside or instead of Stripe.
- Make sure your PayPal keys are correctly set in the
.env file.
Step 4: General Settings
- Configure Site Name and Site Description
- Set Contact Email for support
- Configure SEO Settings (meta tags, keywords)
- Set Email Settings (SMTP configuration if needed)
- Save all changes
✅ Configuration Complete! Your admin settings are now configured. You can start creating
chatbots.
D) Build & Deployment Guide - top
🔨 Production Build Steps
For detailed build instructions, see the Build
Guide document.
Quick Build Summary
- Install Dependencies:
npm install
- Generate Prisma Client:
npm run db:generate
- Set Up Environment Variables:
Ensure your .env file is properly configured (see Section B)
- Run Database Migrations:
npm run db:push
- Build the Application:
npm run build
This will compile TypeScript, optimize assets, and create a production-ready build in the
.next directory.
- Start Production Server:
npm start
The application will be available at http://localhost:3000 (or your configured port).
📖 Full Build Documentation
For comprehensive build instructions, troubleshooting, and deployment options, see:
⚠️ Build Troubleshooting
If you encounter build errors:
- TypeScript Errors: Check type definitions and fix type mismatches
- Prisma Errors: Verify schema and regenerate client with
npm run db:generate
- Memory Issues: Use
NODE_OPTIONS="--max-old-space-size=4096" npm run build
- Environment Variables: Ensure all required variables are set in
.env
See Build Guide - Troubleshooting
Section for detailed solutions.
E) Creating Your First Chatbot - top
- Go to Dashboard → Chatbots → Create New
- Fill in basic information:
- Chatbot name
- Description (optional)
- Language
- Configure AI:
- Select AI model (Gemini recommended)
- Write AI instructions
- Set welcome message
- Add Knowledge Base (optional):
- Create entries with titles and content
- Enable/disable as needed
- Click "Save Chatbot"
- Go to your chatbot's settings page
- Navigate to "Widget" tab
- Choose integration method:
- HTML Integration: Copy code and paste before
</body>
- WordPress Plugin: Download and install plugin
- Shopify Liquid: Use Liquid code for Shopify stores
- Copy the widget code
- Paste into your website
G) Website Usage Guide - top
1. User Registration & Login
- Go to
/register to create a new account
- Fill in email, password, and name
- Verify email (if enabled)
- Login at
/login
2. Dashboard Overview
After login, you'll see:
- Chatbots List: All your chatbots
- Analytics: Usage statistics
- Conversations: Chat history
- Settings: Account settings
3. Creating a Chatbot
- Click "New Chatbot" button
- Fill in chatbot details
- Configure AI settings
- Add knowledge base entries
- Save and get widget code
4. Managing Conversations
- Go to Conversations section
- View all chat history
- Filter by chatbot or date
- Export conversations if needed
5. Widget Customization
- Go to chatbot settings → Appearance tab
- Customize colors, fonts, position
- Preview changes in real-time
- Save and deploy
6. E-commerce Integration
- Go to chatbot settings → E-commerce tab
- Enable WooCommerce or Shopify
- Enter API credentials
- Test product search functionality
H) Key Features - top
🤖 AI Models
Support for multiple AI models:
- Google Gemini (Recommended) - Best performance and pricing
- OpenAI GPT-3.5, GPT-4, GPT-4o, GPT-5
- Automatic model selection based on features
📸 Image Recognition
Chatbots can analyze images uploaded by users using vision-capable models.
💬 Conversations
View and manage all customer conversations from the dashboard with search and filtering.
🎯 Lead Capture
Automatically capture leads from conversations (emails, phones, company names).
📊 Analytics
Track chatbot performance, response times, and customer satisfaction metrics.
🎫 Support Tickets
Manage support tickets and customer issues directly from the platform.
📚 Knowledge Base
Add knowledge base entries to help chatbots answer specific questions accurately.
🛒 E-commerce Integration
Integrate with WooCommerce and Shopify for product search, cart management, and order tracking.
I) Troubleshooting - top
Application won't start
Solution: Check Node.js version (18+), verify database connection, ensure all
dependencies are installed with npm install.
Database connection error
Solution: Verify DATABASE_URL in .env file, ensure database server is running, check
credentials, make sure database exists.
AI not responding
Solution: Check API keys are set correctly (GEMINI_API_KEY or OPENAI_API_KEY), verify
API key has credits, check selected AI model is available, ensure billing is active.
Widget not appearing
Solution: Verify widget script is added before </body> tag, check chatbot ID is
correct, verify API URL is accessible, check CORS settings, ensure domain is configured in admin
settings.
Images not being analyzed
Solution: Ensure you're using a vision-capable model (Gemini models, GPT-4o, GPT-5),
check file size is under 5MB, verify API key supports vision features.
Stripe payments not working
Solution: Verify Stripe keys in .env and admin settings, check webhook is configured
correctly, ensure you're using test keys in development, verify webhook secret matches.
Port already in use
Solution: Change the port or kill the process:
- Windows:
netstat -ano | findstr :3000 then taskkill /PID <pid> /F
- Mac/Linux:
lsof -ti:3000 | xargs kill
J) Support - top
Getting Help:
- Email: LendaLabs@gmail.com
- Response Time: Usually within 24-48 hours
- Documentation: Check this guide first
System Requirements:
- Node.js 18+
- PostgreSQL (or Supabase cloud)
- 2GB RAM minimum (4GB recommended)
- Stable internet connection
- Modern web browser (Chrome, Firefox, Safari, Edge)
Recommended Setup:
- AI Model: Google Gemini (best performance/price)
- Database: Supabase (free cloud option)
- Hosting: Vercel, Railway, or DigitalOcean
🚀 Ready to Start?
You now have everything you need to create and deploy AI-powered chatbots. Follow the steps above to:
- Install dependencies with
npm install
- Configure environment variables
- Set up admin settings
- Create your first chatbot
- Integrate the widget into your website
Start by creating your first chatbot and integrate it into your website!
Thank you for choosing our AI Chatbot SaaS Platform!
LendaSoft
Go To Table of Contents