# <%= name %>

This workspace was generated using the Botonic Nx Plugin.

## Prerequisites

### 1. Backend Setup
```bash
# Clone and setup hubtype-backend
git clone https://github.com/metis-ai/hubtype-backend
cd hubtype-backend
# Follow setup instructions: https://www.notion.so/Laptop-Setup-macOS-0ae7e69f670d40f8b99bf2fb833b59b4
```

### 2. Tunnel Configuration
```bash
# Setup ngrok tunnel for local development
# Replace {YOUR_TUNNEL_SUBDOMAIN} with your actual subdomain
# Target URL: https://{YOUR_TUNNEL_SUBDOMAIN}-be-dev.metis.ai/
```

### 3. AWS SAM CLI Installation
```bash
# Install AWS SAM CLI for local lambda execution
# Follow: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html
```

### 4. Environment Configuration
Create/update `hubtype-backend/local.env` with:

```bash
HUBTYPE_HOST=https://{YOUR_TUNNEL_SUBDOMAIN}-be-dev.metis.ai
EXTRA_ALLOWED={YOUR_TUNNEL_SUBDOMAIN}-be-dev.metis.ai
HUBTYPE_FRONTEND_HOST=http://localhost:4200
CORS_ALLOWED_ORIGINS=http://localhost:4200,http://localhost:4201,http://localhost:4202,http://localhost:3001
# Note: ports 4201, 4202, 3001 are used by botonic v2 serve mode
```

## Getting Started

### Backend Commands
From within `hubtype-backend` directory:

```bash
# Local development mode - uses local lambda
make run-botonic-local

# Remote mode - uses deployed lambda
make run-botonic-remote
```

### Tunnel Setup
Start cloudflare tunnel before running the options below:

```bash
# Replace {YOUR_TOKEN} with your actual Cloudflare tunnel token
docker run --rm --network host cloudflare/cloudflared:latest tunnel --no-autoupdate run --token {YOUR_TOKEN} --url http://localhost:8000
```

### 1. Initialize Bot Monorepo
```bash
# Navigate to your desired directory
cd /path/to/your/workspace

# Generate new bot monorepo (replace {YOUR_BOTS_MONOREPO_NAME})
npx nx generate @botonic/nx-plugin:preset {YOUR_BOTS_MONOREPO_NAME}

# Alternative: Use Nx UI (Cmd+Shift+P → Nx: Generate (UI))
```

### 2. Create Bot Application
```bash
# From within the generated monorepo
cd {YOUR_BOTS_MONOREPO_NAME}

# Generate new bot app (replace {BOT_NAME})
npx nx g @botonic/nx-plugin:bot-app {BOT_NAME}

# Alternative: Use Nx UI (Cmd+Shift+P → Nx: Generate (UI))
```

### 3. Local Development Setup
```bash
# Step 1: Start backend in local mode
cd hubtype-backend
make run-botonic-local

# Step 2: Login to local backend (from bot monorepo)
cd {YOUR_BOTS_MONOREPO_NAME}
nx run {BOT_NAME}:login-to-hubtype --configuration=local

# Step 3: Deploy local runtime (creates bot in database)
nx run {BOT_NAME}:deploy-local-runtime --configuration=local

# Step 4: Start bot in local mode
nx serve {BOT_NAME} --mode=local
```

### 4. Production Deployment
```bash
# Logout from current environment
nx run {BOT_NAME}:logout-from-hubtype

# Login to target environment (dev, dev2, qa, prod)
nx run {BOT_NAME}:login-to-hubtype --configuration=dev2

# Deploy to target environment
nx run {BOT_NAME}:deploy-to-hubtype --configuration=dev2
```


This workspace contains tools and configurations for building Botonic bot applications.

### Available Commands

- `nx g @botonic/nx-plugin:bot-app <name>` - Generate a new bot application
- `nx build <bot-name>` - Build a bot application
- `nx serve <bot-name>` - Serve a bot application for development
- `nx test <bot-name>` - Run tests for a bot application

### AI Commands (Cursor)

- `/update-bot` — Update a Botonic bot to a newer version using Nx migrations. Type `/update-bot` in Cursor chat; it discovers bots, lets you pick one, and runs migrations one version at a time with git branch management.

### Project Structure

```
<%= name %>/
├── apps/                    # Bot applications
├── libs/                   # Shared libraries
├── tools/                  # Build tools and scripts
├── nx.json                 # Nx workspace configuration
├── package.json           # Dependencies and scripts
└── README.md              # This file
```

### Creating Your First Bot

To create a new bot application:

```bash
nx g @botonic/nx-plugin:bot-app my-bot
```

This will create a new bot application in the `apps/my-bot` directory with:
- Basic bot structure
- Routes and actions
- Configuration files
- Build and development scripts

### Development

To start developing your bot:

```bash
# Serve the bot for development
nx serve my-bot

# Build the bot for production
nx build my-bot

# Run tests
nx test my-bot
```

### Learn More

- [Botonic Documentation](https://botonic.io/docs/)
- [Nx Documentation](https://nx.dev/)
- [Hubtype Documentation](https://docs.hubtype.com/)

## Support

For support and questions, please visit our [GitHub repository](https://github.com/hubtype/botonic).
