How nmtechsolutionstuc/botnm works
Purpose and Runtime
makebufferbot is a Node.js Telegram long-polling bot that turns received media and user direction into Buffer drafts requiring manual approval. It also supports Telegram-group publishing and a separate YouTube draft flow. The process starts in src/index.js, which launches the bot plus HTTP endpoints for health checks and temporary media delivery.
Conversation State and Routing
Conversation progress is persisted per chat/user in src/state/conversationStore.js (data/state.json at runtime). The main router and photo-post workflow live in src/bot/handlers.js: collect one or more photos, choose a Sheet-defined mode, collect text/audio, select immediate or scheduled timing, optionally send to a group, then create Buffer drafts. Shared state transitions and UI/message utilities are centralized in src/bot/shared.js.
Mode Configuration Boundary
Google Sheets is the dynamic business configuration source: modes determine prompts, fixed copy, permitted Telegram users, and Buffer channel IDs. src/services/sheets.js reads and caches these rows; it allows adding brands/modes without code changes. Configuration/environment validation and service credentials are handled through src/config.js.
AI Generation and Fallback
AI operations are abstracted so Gemini is preferred but Cloudflare is a resilient fallback. src/services/ai.js orchestrates text generation, audio transcription, and trivia generation across providers. src/services/gemini.js handles Gemini image enhancement and content tasks; src/services/cloudflare.js handles Workers AI image generation/editing and fallback text/audio tasks. This boundary keeps bot flows provider-agnostic while exposing which fallback was used.
Image Command Subflow
src/bot/imageCommands.js implements /generar, /editar, and /mejorar. It creates or transforms media through Cloudflare, rate-limits requests with src/services/rateLimit.js, and requires user confirmation before adding the resulting image into the normal post-drafting conversation. Gemini image-enhancement failures similarly fall back to Cloudflare before retaining the original.
Publishing and Public-Media Boundary
src/services/buffer.js creates pending/scheduled Buffer posts through Buffer’s GraphQL API, using channel IDs selected from the mode configuration. Buffer needs publicly downloadable media rather than raw uploaded bytes; src/services/mediaHost.js temporarily exposes generated/downloaded media via the HTTP endpoint rooted at src/index.js (/media/:id). PUBLIC_BASE_URL is therefore required for media-containing Buffer drafts.
Alternative Delivery Flows
Telegram group posting is intentionally separate from Buffer delivery. src/bot/groupCommands.js parses direct group text/photo, polls, and quizzes; src/services/telegramGroup.js sends confirmed content to the configured Telegram group. src/bot/youtubeFlow.js is a separate state flow for incoming videos, producing distinct AI title/description fields and publishing through a separate YouTube Buffer token/channel configuration.
Infrastructure and External Services
The service depends on Telegram Bot API, Google Sheets API via a service account, Google Gemini, Cloudflare Workers AI, and Buffer GraphQL. It is designed for a persistent Node host such as Render; /health in src/index.js supports external uptime monitoring to prevent free-tier sleep from interrupting Telegram polling. Local persistent state is under data/, so deployments need durable storage if conversation recovery across restarts matters.
Main entry points: handlers.js Post workflow router · index.js App entry & HTTP media · imageCommands.js Image commands · ai.js AI orchestration
Components 21
Runtime
Node process and persistent conversation state.
- App entry & HTTP media · Starts Telegram polling and exposes health and temporary media endpoints.
src/index.js - Conversation store · Persists progress per chat and user.
src/state/conversationStore.js - State file
Telegram flows
Conversation routing and alternative delivery flows.
- Post workflow router · Collects media, mode, content, timing, and delivery choices.
src/bot/handlers.js - Shared conversation UI
src/bot/shared.js - Image commands · Handles generation, editing, enhancement, and confirmation.
src/bot/imageCommands.js - Group commands · Parses direct group posts, polls, and quizzes.
src/bot/groupCommands.js - YouTube draft flow · Builds video-specific titles and descriptions.
src/bot/youtubeFlow.js
Service layer
Provider-agnostic integrations and configuration.
- Configuration · Validates environment and service credentials.
src/config.js - Mode configuration · Caches modes, prompts, permissions, and Buffer channel IDs.
src/services/sheets.js - AI orchestration · Selects Gemini or Cloudflare for generation and transcription.
src/services/ai.js - Gemini provider · Performs content tasks and image enhancement.
src/services/gemini.js - Cloudflare provider · Provides image generation/editing and fallback text or audio tasks.
src/services/cloudflare.js - Image rate limiter
src/services/rateLimit.js - Buffer drafts · Creates pending or scheduled posts through GraphQL.
src/services/buffer.js - Temporary media host · Makes media downloadable for Buffer.
src/services/mediaHost.js - Telegram group publisher · Sends confirmed content to the configured group.
src/services/telegramGroup.js
External platforms
- Telegram Bot API
- Google Sheets API
- Gemini & Workers AI
- Buffer GraphQL API
Connections 29
- App entry & HTTP media → Post workflow router: routes updates
- App entry & HTTP media → Image commands: routes commands
- App entry & HTTP media → Group commands: routes commands
- App entry & HTTP media → YouTube draft flow: routes videos
- App entry & HTTP media → Temporary media host: serves /media/:id
- App entry & HTTP media → Telegram Bot API: long polling
- Post workflow router → Conversation store: reads and writes progress
- Post workflow router → Shared conversation UI: uses transitions and UI
- Post workflow router → Mode configuration: loads selected mode
- Post workflow router → AI orchestration: generates text or transcribes
- Post workflow router → Buffer drafts: creates Buffer draft
- Image commands → Image rate limiter: limits requests
- Image commands → Gemini provider: enhances images
- Image commands → Cloudflare provider: generates, edits, fallback
- Image commands → Post workflow router: confirmed image enters draft flow
- Group commands → Telegram group publisher: publishes confirmed group content
- YouTube draft flow → AI orchestration: creates video metadata
- YouTube draft flow → Buffer drafts: creates YouTube draft
- Conversation store → State file: persists
- Mode configuration → Google Sheets API: reads mode rows
- AI orchestration → Gemini provider: preferred provider
- AI orchestration → Cloudflare provider: fallback provider
- Gemini provider → Gemini & Workers AI: calls
- Cloudflare provider → Gemini & Workers AI: calls
- Buffer drafts → Temporary media host: requires public media URLs
- Buffer drafts → Buffer GraphQL API: creates posts
- Configuration → Mode configuration: supplies credentials
- Configuration → AI orchestration: supplies credentials
- Configuration → Buffer drafts: supplies tokens