# Bonusinos Chatbot

A customizable chatbot for the Bonusinos site that helps users learn about casino bonuses, payment methods, game providers, and responsible gambling.

## Features

- ✅ Easy configuration via `config/chatbot.php`
- ✅ Rule-based responses (works out of the box)
- ✅ Optional OpenAI integration for AI-powered responses
- ✅ Beautiful candy-themed UI matching your site design
- ✅ Livewire-powered for real-time interactions

## Configuration

### Basic Setup

The chatbot is enabled by default. To disable it, add to your `.env`:

```
CHATBOT_ENABLED=false
```

### Customizing Prompts

Edit `config/chatbot.php` to customize:

1. **Greeting Message**: Change the welcome message
2. **Knowledge Base**: Add or modify responses for different topics
3. **Keywords**: Update keyword matching for better intent detection

### Example: Adding a New Topic

```php
// In config/chatbot.php, add to knowledge_base array:
'new_topic' => [
    'keyword1' => 'Response for keyword1',
    'keyword2' => 'Response for keyword2',
],
```

### AI Integration (Optional - FREE Option Available!)

The chatbot supports two AI providers:

#### Option 1: Hugging Face (FREE - No API Key Needed!)

Hugging Face offers free AI models. To enable:

1. Add to your `.env`:
```
CHATBOT_AI_ENABLED=true
CHATBOT_AI_PROVIDER=huggingface
```

2. That's it! No API key needed. The chatbot will use free Hugging Face models.

#### Option 2: OpenAI (Requires API Key)

To use OpenAI instead:

1. Add to your `.env`:
```
CHATBOT_AI_ENABLED=true
CHATBOT_AI_PROVIDER=openai
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gpt-3.5-turbo
```

The chatbot will automatically fall back to rule-based responses if AI fails.

## How It Works

1. **Intent Detection**: The chatbot analyzes user messages for keywords
2. **Response Selection**: Based on detected intent, it selects appropriate responses from the knowledge base
3. **Fallback**: If no match is found, it shows a helpful fallback message

## Customization

### Changing the Chatbot Name

Edit `config/chatbot.php`:
```php
'name' => 'Your Custom Name',
```

### Modifying the UI

The chatbot UI is in `resources/views/livewire/chatbot.blade.php`. It uses Tailwind CSS classes matching your candy theme.

### Adding More Knowledge

Simply add entries to the `knowledge_base` array in `config/chatbot.php`. The chatbot will automatically use them based on keyword matching.

## Files Created

- `config/chatbot.php` - Configuration file
- `app/Services/ChatBotService.php` - Service handling chat logic
- `app/Http/Controllers/ChatBotController.php` - API controller
- `resources/views/components/chatbot-widget.blade.php` - Chatbot UI
- `database/migrations/2025_12_22_180910_create_chatbot_conversations_table.php` - Chat history table

## Database Storage (Optional)

The chatbot can store conversation history in the database. To enable:

1. Run the migration:
```bash
./vendor/bin/sail artisan migrate
```

2. The `chatbot_conversations` table will store:
   - User messages
   - Bot responses
   - Detected intent
   - Whether AI was used
   - Session tracking

## Usage

The chatbot appears automatically on all pages (if enabled). Users can:
- Click the chat button in the bottom-right corner
- Ask questions about bonuses, payments, providers, etc.
- Get instant responses based on your configured knowledge base

## Support

For questions or issues, check the configuration file comments or modify the knowledge base entries to better match your site's content.

