# Original Configuration v1

## Character Configuration

BILL's personality is defined in `src/config/character.ts`:

```typescript
interface CharacterConfig {
  name: string;
  description: string;
  personality: {
    traits: string[];
    tone: string;
    expertise: string[];
  };
  platforms: {
    twitter: {
      maxLength: number;
      useHashtags: boolean;
      style: string;
    };
    telegram: {
      useMarkdown: boolean;
      style: string;
    };
  };
  limitations: string[];
}

export const billCharacter: CharacterConfig = {
  name: "BILL",
  description: "AI assistant specializing in cryptocurrency and technology",
  personality: {
    traits: ["helpful", "knowledgeable", "patient", "honest"],
    tone: "friendly and approachable",
    expertise: ["cryptocurrency", "blockchain", "programming", "technology"]
  },
  platforms: {
    twitter: {
      maxLength: 280,
      useHashtags: true,
      style: "concise and engaging"
    },
    telegram: {
      useMarkdown: true,
      style: "detailed and helpful"
    }
  },
  limitations: [
    "Cannot provide financial advice",
    "Cannot access real-time market data",
    "Cannot execute transactions"
  ]
};
```

## Environment Variables

Create a `.env` file with the following variables:

### Required Variables

```bash
# Twitter OAuth 2.0 Application Credentials
# Get these from https://developer.twitter.com/en/portal/dashboard
TWITTER_CLIENT_ID=your_client_id_here
TWITTER_CLIENT_SECRET=your_client_secret_here  # REQUIRED for confidential clients
TWITTER_REDIRECT_URI=http://localhost:3000/callback  # OAuth callback URL

# Authorized Twitter Account (REQUIRED)
# Only this Twitter username can authenticate with the app
TWITTER_USERNAME=shillbillai

# Security Configuration (REQUIRED for production)
# Secret key for accessing the /login endpoint (generate with: openssl rand -hex 32)
AUTH_SECRET_KEY=your_secret_key_here

# Supabase Database Configuration
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_SECRET_KEY=your_secret_key_here

# Vector Database
PINECONE_API_KEY=your-pinecone-api-key
PINECONE_ENVIRONMENT=your-environment
PINECONE_INDEX=bill-agent

# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here
```

### Optional Variables (with defaults)

```bash
# Timing Configuration (all values in minutes)
REPLY_CHECK_INTERVAL_MIN=2          # How often to check for tweets to reply to
POST_INTERVAL_MIN=240               # How often to post new tweets (4 hours)
INITIAL_POST_DELAY_MIN=1            # Initial delay before first post

# Rate Limiting Configuration
POST_LIMIT=20                       # Maximum posts per day
REPLY_LIMIT=100                     # Maximum replies per day
POST_INTERVAL_MIN_WAIT=120          # Wait at least 2 hours between posts
REPLY_INTERVAL_MIN_WAIT=5           # Wait at least 5 minutes between replies

# Security (optional)
AUTH_ALLOWED_IPS=127.0.0.1,::1      # IP whitelist for /login access (comma-separated)

# AI Model API URLs (optional)
AI_API_URL=http://localhost:3001/api/generate
CHARACTER_ENGINE_API_URL=http://localhost:8000

# Telegram Bot (if using Telegram plugin)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
```

## Setup Instructions

### 1. Twitter OAuth 2.0 Setup

1. Create a Twitter Developer account at <https://developer.twitter.com>
2. Create a new app with OAuth 2.0 enabled
3. Configure OAuth 2.0 settings:
   * **App permissions**: Read and Write
   * **Type of App**: Web App
   * **Callback URLs**: `http://localhost:3000/callback` (for development)
   * **Website URL**: Your application URL
4. Get your Client ID and Client Secret
5. Set `TWITTER_USERNAME` to the account that will authenticate

### 2. Authentication Security

1. Generate a secure authentication key:

   ```bash
   openssl rand -hex 32
   ```
2. Set this as `AUTH_SECRET_KEY` in your environment
3. Optionally set `AUTH_ALLOWED_IPS` to restrict access

### 3. Supabase Setup

1. Create a new Supabase project at <https://supabase.com>
2. Run the SQL schema from `implementation.md`
3. Get your project URL and service role key from Settings → API
4. Enable Row Level Security (RLS) if needed

### 4. Pinecone Setup

1. Create a Pinecone account at <https://pinecone.io>
2. Create a new index:
   * **Name**: `bill-agent`
   * **Dimensions**: 1536 (for OpenAI embeddings)
   * **Metric**: Cosine similarity
3. Get your API key and environment from the dashboard

### 5. OpenAI Setup

1. Create an OpenAI account at <https://platform.openai.com>
2. Generate an API key from the API keys section
3. Ensure you have access to GPT-4 and text-embedding-ada-002

### 6. Telegram Setup (Optional)

1. Create a bot via @BotFather on Telegram
2. Get the bot token
3. Configure webhook URL or use polling mode

## Authentication Flow

The system uses OAuth 2.0 PKCE (Proof Key for Code Exchange) for secure Twitter authentication:

1. **Initial Setup**: Run `bun run auth` to start the authentication flow
2. **Web Interface**: Navigate to `http://localhost:3000`
3. **Auth Key Entry**: Enter your `AUTH_SECRET_KEY` on the web form
4. **Twitter OAuth**: Complete the Twitter authorization flow
5. **Token Storage**: Tokens are automatically saved and refreshed

## Rate Limiting Strategy

The configuration includes built-in rate limiting to comply with Twitter API limits:

* **Daily Limits**: Prevent exceeding daily quotas
* **Minimum Intervals**: Ensure proper spacing between actions
* **Graceful Degradation**: Handle rate limit errors gracefully

## Security Best Practices

* **Environment Isolation**: Use different keys for development/production
* **Key Rotation**: Regularly rotate API keys and secrets
* **Access Control**: Use `AUTH_ALLOWED_IPS` to restrict login access
* **Monitoring**: Track authentication attempts and API usage
* **Backup**: Store environment configurations securely

## Development vs Production

### Development Configuration

```bash
# Faster intervals for testing
REPLY_CHECK_INTERVAL_MIN=1
POST_INTERVAL_MIN=5
POST_INTERVAL_MIN_WAIT=1

# Lower limits for testing
POST_LIMIT=5
REPLY_LIMIT=20
```

### Production Configuration

```bash
# Standard intervals
REPLY_CHECK_INTERVAL_MIN=2
POST_INTERVAL_MIN=240
POST_INTERVAL_MIN_WAIT=120

# Production limits
POST_LIMIT=20
REPLY_LIMIT=100
```
