A Telegram bot built with TypeScript that automates content generation and social media posting. It leverages Google's Generative AI (Gemini) to create engaging content and Puppeteer to interact with Facebook groups.
- AI-Powered Content Generation: Uses Google Gemini (models/gemini-2.0-flash) to generate witty and engaging posts based on keywords.
- Automated Facebook Posting: Automates the process of posting content to specified Facebook groups using Puppeteer.
- Telegram Interface: Interact with the bot directly through Telegram commands.
- MongoDB Integration: Stores user states and post history.
- Docker Support: Easily containerized for deployment.
-
Clone the repository:
git clone https://github.com/ngocpt1906/page-bot.git cd page-bot -
Install dependencies:
yarn install # or npm install
Create a .env file in the root directory with the following environment variables:
# Telegram Bot Token (Get from @BotFather)
BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here # Required for FileHandler
# Google Generative AI API Key
GEMINI_API_KEY=your_gemini_api_key
# MongoDB Connection String
MONGODB_URI=mongodb://localhost:27017/page-bot
# Facebook Authentication (Cookies for Puppeteer)
FACEBOOK_C_USER=your_c_user_cookie_value
FACEBOOK_XS=your_xs_cookie_valueTo run the bot in development mode with hot reloading:
yarn dev
# or
npm run devTo build and run the bot for production:
yarn build
yarn start
# or
npm run build
npm startYou can also run the bot and MongoDB using Docker Compose:
-
Ensure you have Docker and Docker Compose installed.
-
Update
docker-compose.ymlor your.envfile with the necessary credentials. -
Run the containers:
docker-compose up -d
src/index.ts: Entry point of the application.src/botFactory.ts: configuration and command registration for the Telegram bot.src/commands/: Contains command handlers (e.g.,/start,/post).src/crawler/: Puppeteer scripts for browser automation (Facebook interaction).src/services/: Database and file handling services.src/utils/: Utility functions and helper classes.