# Twilio SMS - Quick Reference Guide

## 🚀 Quick Setup (5 Minutes)

### 1. Get Twilio Credentials
- Sign up: https://www.twilio.com/
- Get Account SID & Auth Token from Console
- Buy a phone number

### 2. Configure via API
```bash
POST https://yourdomain.com/admin/sms-settings
{
  "twilio_sid": "ACxxx...",
  "twilio_token": "your_token",
  "twilio_phone_number": "+1234567890",
  "status": true
}
```

### 3. Test
```bash
POST https://yourdomain.com/admin/sms-settings/test
{
  "to": "+1234567890"
}
```

## 📋 Available Templates (Pre-Configured)

| Slug | Name | Variables |
|------|------|-----------|
| `booking-confirmation` | Booking Confirmation | customer_name, service_name, booking_date, booking_time, company_name |
| `booking-reminder` | Booking Reminder | customer_name, service_name, booking_date, booking_time, company_name |
| `booking-cancelled` | Booking Cancelled | customer_name, service_name, booking_date |
| `employee-welcome` | Employee Welcome | employee_name, company_name, job_title, login_link |
| `otp-verification` | OTP Verification | otp, expiry_minutes |
| `password-reset` | Password Reset | otp, expiry_minutes |

## 💻 Code Examples

### Send Booking Confirmation
```php
use App\Helpers\NotificationHelper;

$helper = new NotificationHelper();
$helper->sendBookingConfirmation($booking);
```

### Send Custom SMS
```php
$helper->sendCustomSms('+1234567890', 'Your message', $userId);
```

### Check if SMS Enabled
```php
if ($helper->isSmsEnabled()) {
    // SMS is ready to send
}
```

## 📊 Admin Endpoints

| Action | Endpoint | Method |
|--------|----------|--------|
| Get Settings | `/admin/sms-settings` | GET |
| Update Settings | `/admin/sms-settings` | POST |
| Test SMS | `/admin/sms-settings/test` | POST |
| Get Templates | `/admin/sms-settings/templates` | GET |
| Update Template | `/admin/sms-settings/templates/{id}` | PUT |
| View Logs | `/admin/sms-settings/logs` | GET |
| Get Statistics | `/admin/sms-settings/statistics` | GET |

## 🎯 What I Need From You

### 1. Customize Templates
Edit the templates at: `/admin/sms-settings/templates`

For each template, provide the exact message:
```
"Hi {customer_name}, your booking for {service_name} is confirmed for {booking_date} at {booking_time}. Thank you!"
```

### 2. Define Triggers
Tell me when to send SMS:
- ✅ When booking created → Send confirmation
- ✅ When booking cancelled → Send cancellation
- ✅ When should reminder be sent? (1 day before? 1 hour before?)
- ✅ Any other events?

### 3. Integration Points
I'll integrate SMS into:
- `BookingController` - Confirmation & cancellation
- `EmployeeController` - Welcome messages
- `AuthenticationController` - OTP
- Scheduled tasks - Reminders

## 📁 Files Created

### Database
- `database/migrations/2026_01_19_000001_create_sms_settings_table.php`
- `database/migrations/2026_01_19_000002_create_sms_templates_table.php`
- `database/migrations/2026_01_19_000003_create_notification_logs_table.php`

### Models
- `app/Models/SmsSetting.php`
- `app/Models/SmsTemplate.php`
- `app/Models/NotificationLog.php`

### Services
- `app/Services/TwilioService.php`
- `app/Helpers/NotificationHelper.php`

### Controllers
- `app/Http/Controllers/Admin/SmsSettingController.php`

### Routes
- `routes/backend.php` (added SMS settings routes)

### Documentation
- `TWILIO_SMS_SETUP.md` - Complete guide
- `SMS_INTEGRATION_SUMMARY.md` - Implementation summary
- `SMS_QUICK_REFERENCE.md` - This file

## ✅ Status Check

```bash
# Check if tables exist
php artisan tinker
>>> \Schema::hasTable('sms_settings') // true
>>> \Schema::hasTable('sms_templates') // true
>>> \Schema::hasTable('notification_logs') // true

# Check templates
>>> \App\Models\SmsTemplate::count() // 6

# Check settings
>>> \App\Models\SmsSetting::settings()

# Test routes
php artisan route:list | grep sms-settings
```

## 🔍 Troubleshooting

### SMS Not Sending
1. Check settings: `GET /admin/sms-settings`
2. Check logs: `GET /admin/sms-settings/logs?status=failed`
3. Test connection: `POST /admin/sms-settings/test`
4. Verify phone format: Use +1234567890 format

### Common Errors
- **Authentication failed** → Wrong SID or token
- **Unreachable number** → Invalid phone number
- **Insufficient funds** → Add credits to Twilio

## 📞 Support

1. Check logs in admin panel
2. Review `TWILIO_SMS_SETUP.md`
3. Check Twilio console: https://console.twilio.com/
4. Laravel logs: `storage/logs/laravel.log`

---

**Ready for your templates and trigger specifications!**
