A simple, customizable chatbot for Chatwoot that uses OpenAI to provide intelligent responses. Features conversation history, customizable system prompts, and easy integration with Chatwoot webhooks.
- 🤖 OpenAI Integration: Powered by GPT models for intelligent responses
- 💬 Conversation History: Maintains context across messages
- 🎯 Customizable System Prompt: Define your chatbot's personality and behavior
- 🔄 Auto-Assignment Detection: Stops responding when human agents take over
- 📝 Optional Logging: Track conversations for analysis
- ⚡ Simple Setup: Minimal configuration required
- Node.js (v14 or higher)
- OpenAI API Key
- Chatwoot Account with API Access Token
- Clone or download this repository:
git clone <your-repo-url>
cd chatbot- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env- Edit
.envwith your configuration:
# Required
OPENAI_API_KEY=your_openai_api_key_here
CHATWOOT_API_KEY=your_chatwoot_api_access_token_here
# Optional - Customize these
SYSTEM_PROMPT="You are a helpful assistant..."
OPENAI_MODEL=gpt-4o-mini
TEMPERATURE=0.7
MAX_TOKENS=500- Start the server:
npm start- In your Chatwoot dashboard, go to Settings → Integrations → Webhooks
- Add a new webhook with:
- URL:
http://your-server:3004/api/chatwoot - Events: Select
message_created
- URL:
- Save and test the webhook
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Required |
CHATWOOT_API_KEY |
Your Chatwoot API access token | Required |
CHATWOOT_BASE_URL |
Chatwoot instance URL | https://app.chatwoot.com |
SYSTEM_PROMPT |
Customize your chatbot's behavior | Default assistant prompt |
OPENAI_MODEL |
OpenAI model to use | gpt-4o-mini |
TEMPERATURE |
Response creativity (0-1) | 0.7 |
MAX_TOKENS |
Maximum response length | 500 |
PORT |
Server port | 3004 |
ENABLE_LOGGING |
Save conversations to logs | true |
AUTO_OPEN_CONVERSATION |
Auto-open conversations | true |
Edit the SYSTEM_PROMPT in your .env file to define your chatbot's personality:
SYSTEM_PROMPT="You are a customer support agent for ACME Corp. Be professional, helpful, and always mention our 24/7 support line at 1-800-ACME when relevant."POST /api/chatwoot- Webhook endpoint for ChatwootGET /health- Health check endpoint
The bot maintains the last 10 messages of each conversation for context.
Automatically stops responding when a human agent is assigned to the conversation.
When enabled, saves conversations to logs/YYYY-MM-DD.jsonl files.
Run in development mode with auto-reload:
npm run devFor production, consider using:
- PM2 for process management
- Nginx for reverse proxy
- SSL certificates for HTTPS
MIT