# 📚 Example Code

This folder contains example implementations of all Lua AI Agent features. Use these as reference when building your own agent.

## 📁 What's Inside

### skills/
Example skills and tools demonstrating platform APIs:

| File | What it shows |
|------|--------------|
| `tools/GetWeatherTool.ts` | External API integration |
| `tools/UserDataTool.ts` | User API - get/update user data, chat history, AI generation |
| `tools/ProductsTool.ts` | Products API - CRUD operations |
| `tools/BasketTool.ts` | Baskets API - shopping cart |
| `tools/OrderTool.ts` | Orders API - order management, status & data updates |
| `tools/CustomDataTool.ts` | Data API - custom collections with semantic search |
| `tools/PaymentTool.ts` | Stripe integration, environment variables |
| `tools/SmartBasketTool.ts` | Dynamic job creation from tools |
| `tools/GameScoreTrackerTool.ts` | Jobs API - interval jobs, deactivation, getAll |

### webhooks/
HTTP endpoints for external integrations:

| File | What it shows |
|------|--------------|
| `PaymentWebhook.ts` | Stripe payment notifications, Orders API |
| `UserEventWebhook.ts` | External events, **Templates API** (WhatsApp) |
| `FileUploadWebhook.ts` | **CDN API** - file uploads, Data API |

### jobs/
Scheduled background tasks:

| File | What it shows |
|------|--------------|
| `HealthCheckJob.ts` | Interval schedule, health monitoring |
| `DailyCleanupJob.ts` | Cron schedule, data cleanup |
| `DataMigrationJob.ts` | One-time schedule, batch processing |
| `AbandonedBasketProcessorJob.ts` | **Templates API** (WhatsApp), batch reminders |

### preprocessors/
Message filtering before the agent:

| File | What it shows |
|------|--------------|
| `messageMatching.ts` | Modify/block messages based on content |

### postprocessors/
Response transformation after the agent:

| File | What it shows |
|------|--------------|
| `modifyResponse.ts` | Transform agent responses |

### services/
Helper utilities:

| File | What it shows |
|------|--------------|
| `ApiService.ts` | HTTP client wrapper |
| `GetWeather.ts` | Mock service for testing |

## 🎯 API Coverage

| API | Where it's demonstrated |
|-----|------------------------|
| **User** | `UserDataTool.ts` |
| **Products** | `ProductsTool.ts` |
| **Baskets** | `BasketTool.ts`, `SmartBasketTool.ts` |
| **Orders** | `OrderTool.ts`, `PaymentWebhook.ts` |
| **Data** | `CustomDataTool.ts`, `FileUploadWebhook.ts` |
| **Jobs** | `SmartBasketTool.ts`, `GameScoreTrackerTool.ts` |
| **AI** | `UserDataTool.ts` |
| **Templates** | `UserEventWebhook.ts`, `AbandonedBasketProcessorJob.ts` |
| **CDN** | `FileUploadWebhook.ts` |

## 🚀 How to Use

### Option 1: Copy what you need

```bash
# Copy a tool
cp examples/skills/tools/GetWeatherTool.ts src/skills/tools/

# Copy a webhook
cp examples/webhooks/PaymentWebhook.ts src/webhooks/

# Copy a job
cp examples/jobs/HealthCheckJob.ts src/jobs/
```

### Option 2: Move entire directories

```bash
mv examples/skills src/
mv examples/webhooks src/
mv examples/jobs src/
```

Then import them in your `src/index.ts`.

## 📖 Documentation

- **API Reference:** https://docs.heylua.ai/api
- **Examples Guide:** https://docs.heylua.ai/examples
- **Best Practices:** https://docs.heylua.ai/template/best-practices
