kappa 45e0677ab0 refactor: code quality improvements (P3)
## Type Safety
- Add zod runtime validation for external API responses
  * Namecheap API responses (domain-register.ts)
  * n8n webhook responses (n8n-service.ts)
  * User request bodies (routes/api.ts)
  * Replaced unsafe type assertions with safeParse()
  * Proper error handling and logging

## Dead Code Removal
- Remove unused callDepositAgent function (127 lines)
  * Legacy Assistants API code no longer needed
  * Now using direct code execution
  * File reduced from 469 → 345 lines (26.4% reduction)

## Configuration Management
- Extract hardcoded URLs to environment variables
  * Added 7 new vars in wrangler.toml:
    OPENAI_API_BASE, NAMECHEAP_API_URL, WHOIS_API_URL,
    CONTEXT7_API_BASE, BRAVE_API_BASE, WTTR_IN_URL, HOSTING_SITE_URL
  * Updated Env interface in types.ts
  * All URLs have fallback to current production values
  * Enables environment-specific configuration (dev/staging/prod)

## Dependencies
- Add zod 4.3.5 for runtime type validation

## Files Modified
- Configuration: wrangler.toml, types.ts, package.json
- Services: 11 TypeScript files with URL/validation updates
- Total: 15 files, +196/-189 lines

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 22:06:01 +09:00

🤖 Cloudflare Workers 텔레그램 AI 봇

Cloudflare Workers + D1 + OpenAI를 활용한 서버리스 아키텍처 기반의 지능형 텔레그램 봇입니다. 사용자별 프로필을 자동으로 생성하고 기억하며, 예치금 관리 및 도메인 등록 등의 복잡한 작업을 수행할 수 있습니다.

License TypeScript Cloudflare Workers

📚 문서 안내


주요 기능

  • 🧠 AI 기반 개인화: 대화 내용을 분석하여 사용자의 관심사와 맥락을 기억하는 동적 프로필 시스템
  • 🛠 Function Calling: 날씨, 검색, 계산, 시간 등 다양한 도구를 자연어로 호출
  • 💰 예치금 시스템: 은행 SMS 자동 파싱(AI 폴백 지원) 및 양방향 매칭을 통한 자동 충전
  • 🌐 도메인 관리: 도메인 검색, 추천(AI), 가격 조회, 등록, DNS 관리 통합
  • 서버리스: Cloudflare Workers 위에서 동작하여 별도의 서버 관리 불필요

🚀 빠른 시작 (배포 가이드)

1. 환경 설정

# 의존성 설치
npm install

# Wrangler 로그인
npx wrangler login

2. 데이터베이스 생성

npx wrangler d1 create telegram-conversations
npx wrangler d1 execute telegram-conversations --file=schema.sql

생성된 database_idwrangler.toml에 반영해야 합니다.

3. 비밀키 설정 (Secrets)

npx wrangler secret put BOT_TOKEN       # Telegram Bot Token
npx wrangler secret put OPENAI_API_KEY  # OpenAI API Key
npx wrangler secret put WEBHOOK_SECRET  # Webhook 검증용 Secret

4. 배포 및 웹훅 연결

# 배포
npx wrangler deploy

# 웹훅 설정 (배포된 URL 사용)
curl https://<YOUR_WORKER_URL>/setup-webhook

🛠 기술 스택

분류 기술 비고
Runtime Cloudflare Workers Serverless
DB Cloudflare D1 SQLite
Cache Cloudflare KV Rate Limiting
AI OpenAI GPT-4o-mini Logic & Tools
Fallback Workers AI (Llama 3) Backup AI

🤝 기여 및 문의

버그 신고나 기능 제안은 Issue를 등록해주세요. 소스 코드는 **Gitea**에서 관리됩니다.

Description
Telegram bot with Cloudflare Workers + D1 + OpenAI
Readme MIT 1.1 MiB
Languages
TypeScript 99.7%
Shell 0.3%