Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

on:
push:
pull_request:

jobs:
quality:
runs-on: ubuntu-latest
env:
DEBUG: "False"
SECRET_KEY: ci-secret-key
ALLOWED_HOSTS: localhost,127.0.0.1,testserver
CSRF_TRUSTED_ORIGINS: http://testserver
TIME_ZONE: UTC
BOT_TOKEN: 123456:TEST_TOKEN
IS_POLLING: "True"
WEBHOOK_BASE_URL: https://example.com
TELEGRAM_WEBHOOK_SECRET: ci-webhook-secret
USE_NGROK: "False"
DB_ENGINE: django.db.backends.sqlite3
DB_NAME: /tmp/djangogram-ci.sqlite3
DB_USER: ci
DB_PASSWORD: ci
DB_HOST: localhost
DB_PORT: "5432"
DB_URL: sqlite:////tmp/djangogram-ci.sqlite3
REDIS_URL: redis://localhost:6379/0
REDIS_HOST: localhost
REDIS_PORT: "6379"
REDIS_DB: "0"
CELERY_BROKER_URL: redis://localhost:6379/0
CELERY_RESULT_BACKEND: redis://localhost:6379/0
CELERY_BEAT_SCHEDULER: django_celery_beat.schedulers:DatabaseScheduler
CELERY_TIMEZONE: UTC
CELERY_NOTIFY_INTERVAL: "1"
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ruff

- name: Lint
run: ruff check .

- name: Validate migrations
run: python manage.py makemigrations --check --dry-run

- name: Django system check
run: python manage.py check

- name: Run tests
run: python manage.py test
87 changes: 87 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.pyo
*.pyd
*.so

venv/
env/
.venv/
.env/
ENV/
*.env
*.env.*

# Django
*.log
*.pot
*.pyc
*.sqlite3
db.sqlite3
media/
staticfiles/
static/
node_modules/
.mypy_cache/
pytest_cache/
.coverage
htmlcov/
.DS_Store

settings_local.py
local_settings.py

**/migrations/__pycache__/

# Aiogram
*.session
*.session-journal
bot_data/
logs/
cache/
tmp/

# Docker
docker/*.env
docker/development/*.env
docker/production/*.env
docker/volumes/
docker-compose.override.yml
*.pid
*.sock

# Ignore build artifacts
build/
dist/
*.egg-info/
.eggs/

# VSCode
.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json

# PyCharm / JetBrains
.idea/
.idea/*
!.idea/codeStyles/

# Sublime
*.sublime-project
*.sublime-workspace

# System files
.DS_Store
Thumbs.db
ehthumbs.db
Icon?
Desktop.ini

# GIT / CI RELATED
.gitmodules
.gitconfig
.envrc
.env.bak
67 changes: 43 additions & 24 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
# Djangogram ⚡️
## Production-Ready Django + Aiogram Telegram Bot
# Djangogram

A production-ready **Django + Aiogram Telegram bot** boilerplate.

---
Django + Aiogram Telegram bot template with Docker, Celery, and production webhook support.

## Features

- ✅ Polling mode (development)
- ✅ Webhook mode (production)
- ✅ Ngrok integration (for local webhook testing)
- ✅ Nginx reverse proxy ready
- ✅ Async PostgreSQL operations with Django ORM
- ✅ Celery for background tasks & scheduling
- ✅ Modular handler/router structure
- ✅ Structured logging
- ✅ Dockerized environment (PostgreSQL, Redis, Nginx)

---
- Polling mode for local development
- Webhook mode for production
- Webhook request authentication via `X-Telegram-Bot-Api-Secret-Token`
- Django + Celery + Redis + PostgreSQL
- Nginx reverse proxy for production
- CI checks (lint, migrations, Django checks, tests)

## Getting Started
## Quick Start

### 1. Clone the repository
1. Clone the project:
```bash
git clone git@github.com:ummataliyev/djangogram.git
cd djangogram
```

### 2. Create .env file
Create a .env file for development:
2. Create environment files:
```bash
cp docker/development/.env-example docker/development/.env
cp docker/production/.env-example docker/production/.env
```

Create a .env file for production:
If a value in `.env` contains `$`, escape it as `$$` to avoid Docker Compose interpolation warnings.

3. Check available commands:
```bash
cp docker/development/.env-example docker/production/.env
make help
```

### 3. Check available commands
4. Start development stack:
```bash
make help
make dev-up
```

## Important Production Variables

- `DEBUG=False`
- `ALLOWED_HOSTS=your-domain.com`
- `CSRF_TRUSTED_ORIGINS=https://your-domain.com`
- `WEBHOOK_BASE_URL=https://your-domain.com`
- `TELEGRAM_WEBHOOK_SECRET=<random-strong-secret>`

## Local Webhook Testing (optional)

If you want webhook mode locally, set:

- `IS_POLLING=False`
- `USE_NGROK=True`

and provide a running ngrok endpoint in your environment.

## Quality Checks

```bash
python manage.py makemigrations --check --dry-run
python manage.py check
python manage.py test
```
Loading