# Cambodia Travel Assistant - Quick Setup Checklist

## Pre-Flight Check ✈️

- [x] OpenAI PHP client installed (`openai-php/client` v0.19.2)
- [x] NLP Service created (`app/Services/NLPService.php`)
- [x] ChatGPT Service created (`app/Services/ChatGPTService.php`)
- [x] Dialogflow Service created (`app/Services/DialogflowService.php`)
- [x] Controller refactored (`app/Http/Controllers/AssistantController.php`)
- [x] UI redesigned (`resources/views/assistant/index.blade.php`)
- [x] Routes configured (`routes/web.php`)
- [x] Services config added (`config/services.php`)

## Configuration Steps

### STEP 1: Set OpenAI API Key (REQUIRED for ChatGPT)

```bash
# Open .env file and add:
OPENAI_API_KEY=sk_your_actual_key_here

# Get key from: https://platform.openai.com/account/api-keys
```

### STEP 2: Test the Assistant

```bash
# Start Laravel development server
php artisan serve

# Visit: http://localhost:8000/assistant
# Try asking a question!
```

### STEP 3: Configure Dialogflow (OPTIONAL but recommended)

```bash
# If using Dialogflow, add to .env:
DIALOGFLOW_PROJECT_ID=your-project-id
DIALOGFLOW_CREDENTIALS_PATH=/path/to/credentials.json
DIALOGFLOW_LANGUAGE_CODE=en
```

## Testing Checklist

- [ ] Rule-based responses work (try: "Where should I visit?")
- [ ] NLP intent detection working (check logs)
- [ ] ChatGPT responses appear with green badge (if API key set)
- [ ] Dialogflow responses appear with orange badge (if configured)
- [ ] Sample question buttons work
- [ ] Chat scrolls automatically
- [ ] Typing indicator shows
- [ ] Clear button clears chat history

## Expected Behavior

```
WITHOUT API KEYS:
  Question → NLP Analysis → Rule-Based Match → Default Response
  (Fast, works offline, limited responses)

WITH OPENAI_API_KEY:
  Question → NLP Analysis → Rule-Based → ChatGPT API
  (Intelligent, flexible responses)

WITH DIALOGFLOW:
  Question → NLP Analysis → Rule-Based → Dialogflow → ChatGPT
  (Structured intents + flexible AI)
```

## File Locations

| File                                           | Purpose                          |
| ---------------------------------------------- | -------------------------------- |
| `app/Http/Controllers/AssistantController.php` | Main orchestration controller    |
| `app/Services/NLPService.php`                  | Intent & entity extraction       |
| `app/Services/ChatGPTService.php`              | OpenAI integration               |
| `app/Services/DialogflowService.php`           | Google Dialogflow integration    |
| `resources/views/assistant/index.blade.php`    | Chat UI                          |
| `config/services.php`                          | Service configuration            |
| `.env`                                         | Environment variables (API keys) |
| `routes/web.php`                               | Route definitions                |

## Key Endpoints

```
GET  /assistant              → Show chat UI
POST /assistant/chat         → Send question, get response
POST /assistant/dialogflow-webhook → Dialogflow fulfillment
```

## Response Source Badges

- 🟢 **ChatGPT AI** - Generated by OpenAI
- 🟠 **Dialogflow** - Structured intent response
- 🟣 **Rule-Based** - Predefined pattern match
- ⚫ **Default** - Fallback response

## Common Issues & Solutions

| Issue                           | Solution                                                                |
| ------------------------------- | ----------------------------------------------------------------------- |
| "ChatGPT service not available" | Add `OPENAI_API_KEY` to `.env`                                          |
| Only rule-based responses       | Need to add API key or it's working correctly!                          |
| AssistantController errors      | Check PHP syntax: `php -l app/Http/Controllers/AssistantController.php` |
| Dialogflow not working          | Check `DIALOGFLOW_PROJECT_ID` and credentials path                      |
| CORS errors                     | Add your frontend domain to Laravel config                              |

## Cost Estimation

```
Free Tier:
  - Dialogflow: 180,000 requests/month (free)
  - Development: ~$1-5/month with ChatGPT

Production:
  - Low traffic: $5-20/month
  - Medium traffic: $20-100/month
  - High traffic: Varies by usage
```

## Next Enhancements

1. Add caching for common questions
2. Implement user history/favorites
3. Add analytics tracking
4. Multi-language support
5. Integration with booking APIs
6. Admin dashboard for managing responses
7. Fine-tuning on Cambodia-specific data
8. Voice input/output

---

## Quick Links

- 📚 Full Setup Guide: `AI_TRAVEL_ASSISTANT_SETUP.md`
- 🔑 OpenAI Platform: https://platform.openai.com
- 🔷 Google Dialogflow: https://dialogflow.cloud.google.com
- 📖 Laravel Documentation: https://laravel.com/docs
- 🚀 Deploy Instructions: See `DEPLOYMENT.md` (if available)

---

**Status:** ✅ Ready to deploy after setting `OPENAI_API_KEY`
