- Add Cloudflare Queue for async server provisioning - Producer: callback-handler.ts sends to queue - Consumer: provision-consumer.ts processes orders - DLQ: provision-dlq.ts handles failed orders with refund - Security improvements (from code review): - Store password hash instead of plaintext (SHA-256) - Exclude root_password from logs - Add retryable flag to prevent duplicate instance creation - Atomic balance deduction with db.batch() - Race condition prevention with UPDATE...WHERE status='pending' - Auto-refund on DLQ processing - Validation improvements: - OS image whitelist validation - Session required fields validation - Queue handler refactoring Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
100 lines
3.5 KiB
TOML
100 lines
3.5 KiB
TOML
name = "telegram-summary-bot"
|
|
main = "src/index.ts"
|
|
compatibility_date = "2024-01-01"
|
|
|
|
[ai]
|
|
binding = "AI"
|
|
|
|
[vars]
|
|
ENVIRONMENT = "development" # 로컬: development, 배포 시 secrets로 production 설정
|
|
SUMMARY_THRESHOLD = "20" # 프로필 업데이트 주기 (메시지 수)
|
|
MAX_SUMMARIES_PER_USER = "3" # 유지할 프로필 버전 수 (슬라이딩 윈도우)
|
|
N8N_WEBHOOK_URL = "https://n8n.anvil.it.com" # n8n 연동 (선택)
|
|
# Admin IDs moved to secrets (see bottom of file)
|
|
|
|
# API Endpoints
|
|
OPENAI_API_BASE = "https://gateway.ai.cloudflare.com/v1/d8e5997eb4040f8b489f09095c0f623c/telegram-bot/openai"
|
|
NAMECHEAP_API_URL = "https://namecheap-api.anvil.it.com"
|
|
WHOIS_API_URL = "https://whois-api-kappa-inoutercoms-projects.vercel.app"
|
|
CONTEXT7_API_BASE = "https://context7.com/api/v2"
|
|
BRAVE_API_BASE = "https://api.search.brave.com/res/v1"
|
|
WTTR_IN_URL = "https://wttr.in"
|
|
HOSTING_SITE_URL = "https://hosting.anvil.it.com"
|
|
|
|
# VPS Provider API Endpoints
|
|
LINODE_API_BASE = "https://api.linode.com/v4"
|
|
VULTR_API_BASE = "https://api.vultr.com/v2"
|
|
DEFAULT_SERVER_REGION = "ap-northeast" # 오사카 (Linode: ap-northeast, Vultr: nrt)
|
|
SERVER_RECOMMEND_API_URL = "https://server-recommend.kappa-d8e.workers.dev/api/recommend" # 외부 AI 추천 API (선택)
|
|
|
|
[[d1_databases]]
|
|
binding = "DB"
|
|
database_name = "telegram-conversations"
|
|
database_id = "c285bb5b-888b-405d-b36f-475ae5aed20e"
|
|
|
|
[[d1_databases]]
|
|
binding = "CLOUD_DB"
|
|
database_name = "cloud-instances-db"
|
|
database_id = "bbcb472d-b25e-4e48-b6ea-112f9fffb4a8"
|
|
|
|
[[kv_namespaces]]
|
|
binding = "RATE_LIMIT_KV"
|
|
id = "15bcdcbde94046fe936c89b2e7d85b64"
|
|
preview_id = "0d3af750739e40d4a0324889564d74a7"
|
|
|
|
[[kv_namespaces]]
|
|
binding = "SESSION_KV"
|
|
id = "24ee962396cc4e9ab1fb47ceacf62c7d"
|
|
preview_id = "302ad556567447cbac49c20bded4eb7e"
|
|
|
|
# Service Binding: Worker-to-Worker 호출용 (Cloudflare Error 1042 방지)
|
|
[[services]]
|
|
binding = "SERVER_RECOMMEND"
|
|
service = "server-recommend"
|
|
|
|
# Email Worker 설정 (SMS → 메일 수신)
|
|
# Cloudflare Dashboard에서 Email Routing 설정 필요:
|
|
# 1. Email > Email Routing > Routes
|
|
# 2. deposit@your-domain.com → Worker: telegram-summary-bot
|
|
|
|
# Cron Trigger: 매일 자정(KST) 실행 - 24시간 경과된 입금 대기 자동 취소
|
|
[triggers]
|
|
crons = ["0 15 * * *"] # UTC 15:00 = KST 00:00
|
|
|
|
# Secrets (wrangler secret put 으로 설정):
|
|
# - BOT_TOKEN: Telegram Bot Token
|
|
# - WEBHOOK_SECRET: Webhook 검증용 시크릿
|
|
# - OPENAI_API_KEY: OpenAI API 키
|
|
# - NAMECHEAP_API_KEY: namecheap-api 래퍼 인증 키 (도메인 추천용)
|
|
# - NAMECHEAP_API_KEY_INTERNAL: Namecheap API 키 (내부용)
|
|
# - BRAVE_API_KEY: Brave Search API 키
|
|
# - DEPOSIT_API_SECRET: Deposit API 인증 키 (namecheap-api 연동)
|
|
# - DOMAIN_OWNER_ID: 도메인 관리 권한 Telegram ID (보안상 secrets 권장)
|
|
# - DEPOSIT_ADMIN_ID: 예치금 관리 권한 Telegram ID (보안상 secrets 권장)
|
|
# - LINODE_API_KEY: Linode Personal Access Token
|
|
# - VULTR_API_KEY: Vultr API Key
|
|
# - SERVER_ADMIN_ID: 서버 관리 알림 수신자 Telegram ID
|
|
|
|
# ============================================
|
|
# Queue Configuration (Server Provisioning)
|
|
# ============================================
|
|
|
|
# Queue Producer 바인딩
|
|
[[queues.producers]]
|
|
queue = "server-provision-queue"
|
|
binding = "SERVER_PROVISION_QUEUE"
|
|
|
|
# Queue Consumer 바인딩 (같은 Worker에서 처리)
|
|
[[queues.consumers]]
|
|
queue = "server-provision-queue"
|
|
max_retries = 3
|
|
max_batch_size = 1
|
|
max_batch_timeout = 30
|
|
max_concurrency = 3
|
|
dead_letter_queue = "provision-dlq"
|
|
|
|
# Dead Letter Queue Consumer
|
|
[[queues.consumers]]
|
|
queue = "provision-dlq"
|
|
max_retries = 0
|