# Sentient AI — WordPress Chatbot Plugin

AI-powered chatbot plugin for WordPress with FAQ management, multiple AI provider support, and advanced features.

## Features

### Core Chatbot
- **Multiple AI Providers**: OpenAI, Claude (Anthropic), Google Gemini, OpenRouter, Hugging Face
- **FAQ Management**: Create, import, and manage FAQs that the chatbot uses to answer questions
- **Pre-Chat Form**: Collect visitor name and email before they start chatting
- **Chat History**: Session-based conversation history with export capability
- **Content-Aware Responses**: AI reads the current page to give relevant answers

### Intelligence
- **Self-Learning AI**: Learns from user feedback, clusters topics, suggests new FAQs
- **Empathy Engine**: Detects user emotion and adapts response tone
- **Confidence Scoring**: Shows confidence badges (High/Medium/Low) on AI responses
- **Source Attribution**: Displays which pages or FAQs the AI used
- **Sentiment Analytics**: Tracks user emotion trends over time

### Privacy & Control
- **Local Brain**: Browser-based FAQ search with fuzzy matching — zero API costs
- **Privacy Mode**: Chatbot uses only local FAQ database, no external APIs
- **Business Hours**: Show chatbot only during specified hours
- **Page Rules**: Show/hide on specific pages or for specific user roles
- **Rate Limiting**: Max queries per user per day

### WordPress Integration
- **Autopilot**: Admin-only commands through the chatbot (create posts, manage plugins, etc.)
- **WooCommerce**: Product info, order status, and cart details
- **Setup Wizard**: Quick 3-step setup process

### MCP Server
- **Model Context Protocol**: Connect AI agents (Claude Desktop, Cursor, etc.) to your WordPress site
- **8 Tools**: Chat, FAQ search, FAQ management, contacts, stats, WordPress management
- **Resources & Prompts**: Read-only data sources and pre-built prompts for AI agents
- **API Key Auth**: Secure Bearer token authentication

### GEO Scanner
- **Generative Engine Optimization**: Analyze content for AI search engine citability
- **10-Factor Analysis**: Content length, structured data, FAQs, citations, statistics, E-E-A-T, structure, meta, lists, titles
- **Auto-Fix**: One-click fixes for schema markup and FAQ sections
- **Scoring**: 0-100 score with actionable suggestions

## Installation

1. Upload the `sentient-ai` folder to `/wp-content/plugins/`
2. Activate the plugin through the **Plugins** menu
3. Go to **Sentient AI → Settings** and configure your AI provider
4. Enter your API key in the **AI Providers** tab
5. Enable the chatbot in the **General** tab

## Configuration

### Quick Start
1. **General Tab**: Toggle "Enable Chatbot" on
2. **AI Providers Tab**: Select your provider and enter API key
3. **Widget Tab**: Customize appearance and enable Pre-Chat Form
4. **Features Tab**: Enable advanced features like Self-Learning AI, Empathy Engine

### Without API Key
The chatbot works without an API key using:
- **Browser FAQ Matcher**: Automatically searches FAQs in the browser
- **Local Brain**: Enable in Features tab for fuzzy FAQ search
- **FAQ Keyword Match**: Server-side keyword matching

### MCP Server Setup
1. Go to **Sentient AI → MCP Server**
2. Toggle "Enable MCP Server" on
3. Copy the API Key
4. Add to your MCP client config (see examples on the page)

### GEO Scanner
1. Go to **Sentient AI → GEO Scanner**
2. Click on any content to scan
3. Review the score and suggestions
4. Apply quick fixes for instant improvements

## Admin Pages

| Page | Description |
|---|---|
| Sentient AI (Settings) | Main settings with 6 tabs: General, Providers, Widget, Features, Privacy, Help |
| Query Logs | All chatbot queries with confidence scores |
| Conversations | Full conversation threads by session |
| Low Confidence | Queries where AI was unsure — use to improve FAQs |
| Sentiment Analytics | User emotion trends over time |
| Learning Dashboard | AI learning progress and topic clusters |
| Autopilot Log | Admin commands executed through chatbot |
| Insights | AI-generated recommendations |
| Contacts | Visitor contacts from Pre-Chat Form |
| MCP Server | MCP Server configuration and client examples |
| GEO Scanner | Content analysis for AI search optimization |

## Shortcodes

```
[sentient_ai_chat]
```
Embed the chatbot anywhere on your site.

## REST API Endpoints

| Endpoint | Method | Description |
|---|---|---|
| `/wp-json/sentientai-mcp/v1` | POST | MCP Server (JSON-RPC 2.0) |
| `/wp-json/sentientai-mcp/v1/sse` | GET | MCP Server (SSE transport) |

## Requirements

- WordPress 5.0+
- PHP 7.4+
- At least one AI provider API key (or use Local Brain/FAQ-only mode)

## License

GPL v2 or later

## Changelog

### 2.14.0
- **CRITICAL**: Server-side session secrets replace client-side hash — prevents session forgery
- **CRITICAL**: SQL injection fix in Vector DB admin panel
- **HIGH**: WooCommerce webhook hardening — secret required, event type filtering
- **HIGH**: Session lifecycle management with 24-hour auto-pruning
- Fixed: Chatbot clear history now properly resets session secret

### 2.13.0
- Added MCP Server support (Model Context Protocol)
- Added GEO Scanner (Generative Engine Optimization)
- Added browser-based FAQ matcher (works without API key)
- Fixed welcome message not showing
- Fixed Enable Chatbot setting resetting on tab save
- Fixed Pre-Chat Form session persistence
- Fixed role-limit query settings saving
- Added Help tab with complete feature documentation
- Added friendly error message when no API key configured

### 2.6.0
- Pre-Chat Form improvements
- Contact Manager enhancements
- Bug fixes and stability improvements

### 2.5.0
- Self-Learning AI
- Empathy Engine
- Content-Aware Responses
- WordPress Autopilot

### 2.0.0
- Local Brain (browser-based FAQ search)
- Privacy Mode
- Multiple AI provider support
- WooCommerce integration

### 1.0.0
- Initial release
