Skip to content

AI-powered marketing chatbot with intelligent product search, persistent chat history, and aggressive sales conversion. Built with Next.js, PostgreSQL, and GPT-3.5 Turbo.

Notifications You must be signed in to change notification settings

Tanish2002/marketbot

Repository files navigation

MarketBot Agent

An AI-powered marketing chatbot with intelligent product search, persistent chat history, and aggressive sales conversion optimization.

Features

  • πŸ€– AI-Powered Sales Agent - GPT-3.5 Turbo with aggressive sales prompting
  • πŸ” Intelligent Product Search - Multi-strategy search with full-text capabilities
  • πŸ’¬ Persistent Chat History - Cross-session conversation management
  • ⚑ Real-time Streaming - Token-by-token response streaming
  • πŸ“± Responsive Design - Mobile-first UI with modern components
  • πŸ”’ Secure & Validated - Input sanitization and type-safe APIs

Tech Stack

  • Frontend: Next.js 14+, TypeScript, Tailwind CSS, shadcn/ui
  • Backend: Node.js, PostgreSQL, Drizzle ORM
  • AI: OpenAI GPT-3.5 Turbo via Vercel AI SDK
  • Database: PostgreSQL with GIN indexes for full-text search

Prerequisites

  • Node.js 18+
  • PostgreSQL 13+
  • OpenAI API key

Installation

  1. Clone the repository

    git clone <repository-url>
    cd marketbot-agent
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp .env.example .env.local

    Configure the following variables:

    DATABASE_URL="postgresql://username:password@localhost:5432/marketbot"
    OPENAI_API_KEY="your-openai-api-key"
    NODE_ENV="development"
  4. Set up the database

    # Create database
    createdb marketbot
    
    # Run migrations
    npm run db:migrate
    
    # Seed sample data (optional)
    npm run db:seed
  5. Start the development server

    npm run dev

    Open http://localhost:3000 in your browser.

Database Setup

The application uses PostgreSQL with advanced indexing for optimal search performance. Key features:

  • GIN indexes for full-text search on product names and descriptions
  • JSONB support for flexible product features and tags
  • Connection pooling for scalable concurrent access
  • Automatic session cleanup for expired conversations

Schema Overview

  • products - Product catalog with full-text search capabilities
  • chat_sessions - User conversation sessions with auto-expiration
  • chat_messages - Individual messages with product context linking

API Endpoints

Products

  • GET /api/products - Search products with filtering and pagination
  • GET /api/products/[id] - Get single product details
  • POST /api/products - Create new product
  • PUT /api/products/[id] - Update product
  • DELETE /api/products/[id] - Delete product

Chat

  • POST /api/chat/stream - Stream AI responses
  • GET /api/chat/history - Get conversation history
  • DELETE /api/chat/history - Clear conversation history
  • POST /api/chat/history/save - Save message

Sessions

  • GET /api/chat/sessions - List user sessions
  • DELETE /api/chat/sessions - Delete session
  • PUT /api/chat/sessions/rename - Rename session

Usage

  1. Start a conversation - The AI agent will greet you and ask about your product interests
  2. Search for products - Ask about specific products or categories
  3. Get recommendations - The AI will suggest relevant products based on your queries
  4. View chat history - Access previous conversations from the sidebar
  5. Manage sessions - Rename or delete conversation sessions

Configuration

Environment Variables

Variable Description Required
DATABASE_URL PostgreSQL connection string Yes
OPENAI_API_KEY OpenAI API key for GPT-3.5 Turbo Yes
NODE_ENV Environment (development/production) Yes

Database Configuration

Connection pooling settings (adjust in db/index.ts):

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  max: 10,                    // Maximum connections
  idleTimeoutMillis: 30000,   // Close idle connections
  connectionTimeoutMillis: 2000
});

Development

Scripts

npm run dev          # Start development server
npm run build        # Build for production
npm run start        # Start production server
npm run lint         # Run ESLint
npm run type-check   # Run TypeScript checks
npm run db:migrate   # Run database migrations
npm run db:seed      # Seed sample data

Project Structure

β”œβ”€β”€ app/                 # Next.js app directory
β”‚   β”œβ”€β”€ api/            # API routes
β”‚   β”œβ”€β”€ globals.css     # Global styles
β”‚   β”œβ”€β”€ layout.tsx      # Root layout
β”‚   └── page.tsx        # Home page
β”œβ”€β”€ components/         # React components
β”‚   β”œβ”€β”€ chat/          # Chat-related components
β”‚   └── ui/            # UI components (shadcn/ui)
β”œβ”€β”€ db/                # Database configuration
β”‚   β”œβ”€β”€ index.ts       # Database connection
β”‚   └── schema.ts      # Drizzle schema
β”œβ”€β”€ lib/               # Utility libraries
β”‚   β”œβ”€β”€ chat-history.ts # Chat history service
β”‚   β”œβ”€β”€ db-service.ts   # Database service
β”‚   β”œβ”€β”€ prompt.ts       # AI prompt configuration
β”‚   └── validation.ts   # Input validation schemas
└── public/            # Static assets

Deployment

Production Checklist

  1. Set up production PostgreSQL database
  2. Configure environment variables
  3. Run database migrations
  4. Build and deploy the application
  5. Set up health monitoring on /api/health

Performance Considerations

  • Database connection pooling is configured for production use
  • GIN indexes optimize search performance
  • Session cleanup prevents memory leaks
  • Response streaming improves perceived performance

About

AI-powered marketing chatbot with intelligent product search, persistent chat history, and aggressive sales conversion. Built with Next.js, PostgreSQL, and GPT-3.5 Turbo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published