A robust, high-performance Golang Telegram bot for downloading Instagram content, including Stories, Highlights, Posts, and Reels. Built with a focus on reliability, scalability, and a great user experience.
- Automatic Story Subscription: Subscribe to users and automatically receive their new stories.
- On-Demand Downloads: Fetch content instantly with simple commands.
/story <username>
: Get all current stories./highlights <username>
: Get all highlight albums./post <url>
: Download a single post or an album./reel <url>
: Download a Reel video.
- High Performance: Utilizes a worker pool (
ants
) to handle multiple scraping jobs concurrently. - Reliable & Resilient:
- Smart retry mechanism with backoff for network or scraper failures.
- User-friendly feedback with real-time status updates (e.g., "Fetching...", "Retrying...").
- Clean Architecture:
- Well-structured project layout (
cmd
,internal
,pkg
). - Dependency Injection with
uber/fx
for a modular and testable codebase.
- Well-structured project layout (
- Containerized: Fully containerized with Docker and Docker Compose for easy deployment.
- CI/CD Pipeline: Automated testing, security scanning (
Trivy
,Dockle
), and image publishing via GitHub Actions.
- Go (version 1.21 or higher)
- Docker & Docker Compose (for containerized deployment)
- A Telegram Bot Token from @BotFather
-
Clone the repository:
git clone https://github.com/orgball2608/insta-parser-telegram-bot.git cd insta-parser-telegram-bot
-
Set up environment variables: Create a
.env
file from the example:cp .env.example .env
Then, fill in your details in the
.env
file, especiallyTELEGRAM_BOT_TOKEN
. -
Run the application: The project uses
air
for live-reloading. Themake run
command will handle everything.make run
If you don't have
air
, install it with:go install github.com/cosmtrek/air@latest
.
The easiest way to get the bot and its database up and running.
-
Set up environment variables: Create and configure your
.env
file as described above. -
Build and run with Docker Compose:
docker-compose up --build -d
The
-d
flag runs the containers in detached mode. -
To view logs:
docker-compose logs -f app
-
To stop:
docker-compose down
The project follows a standard Go project layout to maintain a clean and scalable architecture.
.
├── cmd/ # Main application entrypoint
├── internal/ # Private application code (not for export)
│ ├── app/ # Application setup, dependency injection (FX)
│ ├── command/ # Telegram command handlers
│ ├── domain/ # Core business entities (Story, Post, etc.)
│ ├── instagram/ # Instagram client logic (scraping adapter)
│ ├── parser/ # Scheduled jobs and processing logic
│ ├── repositories/ # Data access layer (PostgreSQL)
│ │ ├── currentstory/ # Current stories repository
│ │ ├── highlights/ # Highlights repository
│ │ ├── story/ # Stories repository
│ │ ├── subscription/ # Subscriptions repository
│ │ └── fx/ # Repository dependency injection
│ └── telegram/ # Telegram client implementation
├── pkg/ # Public libraries safe to use by other projects
│ ├── config/ # Configuration handling
│ ├── errors/ # Error handling utilities
│ ├── logger/ # Logging utilities
│ ├── middleware/ # HTTP middleware
│ ├── pgx/ # PostgreSQL connection utilities
│ └── retry/ # Retry mechanism for operations
├── migrations/ # Database migrations (Goose)
└── tools/ # Supporting tools for development
└── migrate/ # Migration tool
/start
,/help
- Shows the help message./subscribe <username>
- Subscribe to new stories from a user./unsubscribe <username>
- Unsubscribe from a user./listsubscriptions
- Show your current subscriptions./story <username>
- Fetch current stories./highlights <username>
- Fetch all highlight albums./post <url>
- Download a post or album./reel <url>
- Download a Reel.
This project comes with a handy Makefile
for common development tasks.
make run
: Run the app locally with live-reloading.make build
: Build the application binary.make test
: Run all tests with coverage.make lint
: Run the GolangCI-Lint linter.make mock
: Generate mocks using Mockery.make migrate-up
: Apply all pending database migrations.make migrate-down
: Rollback the last database migration.make create-migration name=<name>
: Create a new SQL migration file.
Contributions are welcome! If you have ideas for new features or improvements, feel free to open an issue or submit a pull request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.