A powerful, scalable AI chatbot creation platform built on Cloudflare's edge network. Create custom AI personalities, train them with your knowledge base, and deploy them anywhere.
- Personality Customization: Create unique AI personalities with custom names, ages, roles, and tones
- Knowledge Base Training: Upload text files to train your bot with specific information
- Vector Search: Uses Cloudflare Vectorize for intelligent, context-aware responses
- Multi-Model Fallback: 158+ AI models with automatic fallback for maximum reliability
- Real-time Chat: Interactive chat interface to test and refine your bot
- Export Ready: Generate embeddable code for your website
- Persistent Storage: D1 database for bot persistence and session management
- Session Persistence: KV storage for chat history across browser sessions and embedded widgets
- Widget Integration: Embeddable chatbot widget with persistent conversations
- Frontend: Modern, responsive UI built with Tailwind CSS
- Backend: Cloudflare Workers for serverless API endpoints
- Database: Cloudflare D1 for structured data storage
- Vector Database: Cloudflare Vectorize for semantic search
- AI Processing: Cloudflare AI for embeddings and text processing
niche-bot-project/
βββ src/
β βββ index.js # Cloudflare Worker backend logic
βββ public/
β βββ index.html # Main HTML interface
β βββ app.js # Frontend JavaScript logic
βββ wrangler.toml # Cloudflare configuration
βββ package.json # Dependencies and scripts
βββ README.md # This file
- Node.js 18+ installed
- Cloudflare account with Workers enabled
- Wrangler CLI installed globally
npm installnpm install -g wranglerwrangler loginwrangler d1 create niche-bot-dbImportant: Copy the database_id from the output and update it in wrangler.toml.
wrangler d1 execute niche-bot-db --command="CREATE TABLE bots (id TEXT PRIMARY KEY, personality TEXT, created_at TEXT);"wrangler vectorize create niche-bot-kb-index --dimensions=384 --metric=cosinewrangler kv namespace create "SESSIONS"Important: Copy the id from the output and update it in wrangler.toml.
Edit wrangler.toml and replace the placeholder values with your actual:
- D1 database ID
- KV namespace ID
wrangler deployThe main configuration file that defines:
- Worker name and entry point
- D1 database bindings
- Vectorize index bindings
- AI model bindings
- Static asset serving
The following services are automatically configured:
- D1 Database: Stores bot personalities and metadata
- Vectorize: Handles semantic search and knowledge retrieval
- AI Models: Provides embedding and text processing capabilities
- KV Storage: Stores chat sessions and conversation history
Creates a new bot session with personality data.
Request Body:
{
"personality": {
"name": "Eva",
"age": 28,
"hair": "Silver",
"role": "Knowledgeable historian",
"tone": "Witty and slightly sarcastic",
"bio": "An AI who has absorbed the entire library of Alexandria..."
}
}Response:
{
"success": true,
"botId": "uuid-here"
}Trains a bot with uploaded text files.
Request: Multipart form data with files field containing .txt files.
Response:
{
"success": true,
"message": "Knowledge base updated with X document chunks."
}Handles chat interactions with the trained bot.
Request Body:
{
"messages": [
{"role": "user", "content": "Hello, what do you know about ancient Egypt?"}
]
}Response:
{
"success": true,
"reply": "Based on my knowledge base, I can tell you that...",
"modelUsed": "gpt-4"
}Saves chatbot session data including chat history.
Request Body:
{
"chatHistory": [
{"role": "user", "content": "Hello!"},
{"role": "assistant", "content": "Hi there!"}
],
"personality": {
"name": "Eva",
"role": "Assistant"
}
}Loads chatbot session data.
Response:
{
"success": true,
"session": {
"chatHistory": [...],
"personality": {...},
"lastUpdated": "2025-08-29T..."
}
}Gets bot data for embedded widgets.
Response:
{
"success": true,
"personality": {
"name": "Eva",
"role": "Assistant",
"bio": "..."
}
}Handles chat for embedded widgets with session persistence.
Request Body:
{
"messages": [...],
"sessionId": "session_123456"
}Loads widget session data.
Response:
{
"success": true,
"session": {
"chatHistory": [...],
"personality": {...}
}
}- Fill out the personality form with your desired bot characteristics
- Click "Create & Save Personality" to save the bot
- The bot is now ready for training and chat
- Upload .txt files containing knowledge you want your bot to learn
- Click "Train with New Files" to process and store the information
- The bot will chunk the text and create vector embeddings for semantic search
- Type messages in the chat interface
- The bot will search its knowledge base for relevant context
- Responses are generated using the selected AI model with personality consistency
- Click the "Export" button to generate embeddable code
- Copy the generated HTML/JavaScript code
- Paste it into your website to embed the chatbot
- The widget will automatically persist conversations across page visits
Example embed code:
<div data-bot-id="your-bot-id"></div>
<script src="https://your-domain.com/widget.js" defer></script>- Persistent Sessions: Chat history is saved and restored automatically
- Responsive Design: Adapts to different screen sizes
- Real-time Chat: Instant responses with typing indicators
- Session Management: Each user gets their own conversation session
- All API keys are stored securely in environment variables
- File uploads are limited to .txt files
- Vector embeddings are isolated per bot ID
- Database queries use parameterized statements to prevent injection
- Edge Computing: Deployed on Cloudflare's global network for low latency
- Vector Search: Sub-second response times for knowledge retrieval
- Model Fallback: Automatic failover ensures high availability
- Caching: Built-in caching for improved response times
- Database Connection Error: Verify your D1 database ID in
wrangler.toml - Vectorize Error: Ensure your Vectorize index is created and accessible
- AI Model Failures: Check that your API keys are valid and have sufficient credits
Run in development mode for detailed logging:
wrangler devThis architecture is designed to scale automatically:
- Workers: Automatically scales based on demand
- D1: Handles concurrent database connections efficiently
- Vectorize: Optimized for high-throughput vector operations
- AI Models: Multiple fallback options ensure reliability
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Check the troubleshooting section above
- Review Cloudflare Workers documentation
- Open an issue on GitHub
Built with β€οΈ on Cloudflare's edge network