# LinkedIn Bot

A LinkedIn automation tool with a Telegram bot interface and a full web dashboard. Generate AI-powered posts, schedule daily auto-posting, manage a topic queue, and publish to LinkedIn — all from your browser or Telegram.

## Run & Operate

- `pnpm --filter @workspace/api-server run dev` — run the API server (port 8080)
- `pnpm --filter @workspace/linkedin-bot run dev` — run the web dashboard (port 21324)
- `pnpm run typecheck` — full typecheck across all packages
- `pnpm run build` — typecheck + build all packages
- `pnpm --filter @workspace/api-spec run codegen` — regenerate API hooks and Zod schemas from the OpenAPI spec
- `pnpm --filter @workspace/db run push` — push DB schema changes (dev only)
- Required env: `DATABASE_URL` — Postgres connection string (auto-provisioned)

## Required Secrets

Set these in the Replit Secrets tab:

- `LINKEDIN_ACCESS_TOKEN` — LinkedIn OAuth token with `w_member_social` permission
- `TELEGRAM_BOT_TOKEN` — From @BotFather on Telegram (/newbot)
- `GROQ_API_KEY` — From console.groq.com (optional, for AI generation; falls back to sample posts)

## Stack

- pnpm workspaces, Node.js 24, TypeScript 5.9
- API: Express 5 + Telegraf (Telegram bot) + node-cron (scheduling)
- DB: PostgreSQL + Drizzle ORM
- Frontend: React + Vite + shadcn/ui + Tailwind CSS
- AI: Groq API (llama-3.1-8b-instant)
- LinkedIn: ugcPosts API
- Validation: Zod (`zod/v4`), `drizzle-zod`
- API codegen: Orval (from OpenAPI spec)

## Where things live

- `lib/api-spec/openapi.yaml` — single source of truth for API contracts
- `lib/db/src/schema/linkedin.ts` — DB schema (post_history, queue, schedule, persona)
- `artifacts/api-server/src/routes/` — Express route handlers
- `artifacts/api-server/src/lib/` — LinkedIn, AI (Groq), Telegram bot, storage helpers
- `artifacts/linkedin-bot/src/pages/` — React dashboard pages
- `artifacts/linkedin-bot/src/App.tsx` — routing setup

## Architecture decisions

- **No auth on the web dashboard** — it's a personal tool deployed privately; Telegram bot serves as the mobile interface.
- **DB-backed state** — post history, queue, schedule, and persona stored in PostgreSQL (not JSON files).
- **Groq for AI, fallback to local posts** — if GROQ_API_KEY is missing, 8 curated sample posts are used.
- **node-cron polls every minute** — compares current hour/minute to stored schedule; fires auto-post on match.
- **Telegraf polling mode** — simpler than webhook setup; suitable for development and personal use.

## Product

- **Dashboard** — overview stats, quick generate-and-publish flow
- **Compose** — AI post generation with tone/length controls, editable preview, one-click publish
- **Queue** — topic queue for scheduled auto-posting (max 7 items)
- **Schedule** — daily auto-post time with timezone support
- **History** — searchable log of all published posts
- **Persona** — bio that shapes AI post generation voice
- **Settings** — token status with setup instructions
- **Telegram bot** — /post, /topic, /queue, /schedule, /history, /persona, /status commands

## User preferences

- User speaks Hindi/Urdu informal style; keep replies simple and direct.

## Gotchas

- After changing the OpenAPI spec: always run codegen before using updated types.
- After adding new DB tables: run `pnpm --filter @workspace/db run push`.
- After rebuilding `lib/db`: run `pnpm run typecheck:libs` so artifacts pick up new exports.
- The Telegram bot uses long-polling — don't run two instances simultaneously.
- LinkedIn access tokens expire; if publishing fails, the token likely needs renewal.
