This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Telegram bot for task scheduling and calendar management, built with TypeScript and deployed on Vercel. It integrates with Google Calendar and Google Sheets for task storage and scheduling.
- Telegram Webhook Handler (
api/telegram-webhook.ts) - Processes incoming Telegram messages and commands - Task Parser (
lib/task-parser.ts) - Uses OpenAI GPT-4o-mini to parse natural language task descriptions into structured tasks - Scheduler (
lib/scheduler.ts) - Manages Google Calendar integration and time slot scheduling
- User sends natural language message to Telegram bot
- Webhook receives message, validates chat ID for security
- TaskParser uses OpenAI to extract structured task data (title, duration, priority, energy level, timing preferences)
- Scheduler finds optimal time slots within working hours (9-5 EST, Mon-Fri by default)
- Task is added to Google Calendar and logged to Google Sheets
- User receives confirmation with formatted task details
Since this is a simple TypeScript project without build scripts:
- Install dependencies:
npm install - Type checking:
npx tsc --noEmit(no tsconfig.json present) - Local development: Vercel CLI for serverless function testing
TELEGRAM_BOT_TOKEN- Bot token from @BotFatherTELEGRAM_CHAT_ID- Authorized chat ID for securityOPENAI_API_KEY- For natural language parsingGOOGLE_SERVICE_ACCOUNT_KEY- JSON credentials for Google APIsGOOGLE_CALENDAR_ID- Target calendar IDGOOGLE_SHEET_ID- Task logging spreadsheet ID
- Only responds to messages from whitelisted
TELEGRAM_CHAT_ID - Always returns 200 to Telegram to prevent retry loops
- Works in America/New_York timezone
- Converts EDT times to UTC for calendar storage
- Working hours: 9 AM - 5 PM, Monday-Friday (unless weekend explicitly mentioned)
- 30-minute scheduling intervals (buffer removed as of Aug 2025 for conservative time estimates)
- AI determines energy level based on task type (high: creative work, medium: admin, low: meetings)
- Priority scoring combines urgency (1-5), impact (1-5), and confidence (0.1-1.0)
- Intelligent time slot selection based on energy requirements and user preferences
- Comprehensive error messages sent back to user via Telegram
- All errors logged to console with full stack traces
- Graceful degradation when AI parsing fails
api/ # Vercel serverless functions
├── hello.ts # Simple health check endpoint
└── telegram-webhook.ts # Main webhook handler
lib/ # Core business logic
├── task-parser.ts # OpenAI-powered task parsing
└── scheduler.ts # Google Calendar/Sheets integration
Goal: Extend application to support multiple users with individual preferences
User Profile Schema:
interface UserProfile {
telegramUserId: string;
telegramChatId: string;
preferences: {
bufferMinutes: number; // 0-60 minutes between events
workingHours: { start: string; end: string };
timezone: string;
allowWeekends: boolean;
defaultEnergyLevel: "high" | "medium" | "low";
schedulingLookahead: number; // days
};
googleCalendarId: string;
googleSheetId: string;
createdAt: Date;
updatedAt: Date;
}Implementation Plan:
- Add database layer for user profiles
- Replace single
TELEGRAM_CHAT_IDwith user-based authentication - Modify
Scheduler.filterConflictingSlots()to accept configurable buffer from user preferences - Add Telegram commands for preference management (e.g.,
/settings buffer 5) - Design migration strategy from single-user env vars to multi-user database