Skip to content

Aggregate posts from several channels and send it at schedule time

License

Notifications You must be signed in to change notification settings

borisevich-a-v/telegram_posts_aggregator

Folders and files

NameName
Last commit message
Last commit date
Oct 10, 2024
Dec 25, 2024
Dec 25, 2024
Jan 1, 2025
Jan 1, 2025
Dec 25, 2024
May 4, 2024
Jan 1, 2025
Dec 24, 2024
Dec 24, 2024
Nov 17, 2024
Dec 24, 2024
Nov 26, 2024
Dec 25, 2024
Dec 25, 2024
Dec 25, 2024
May 4, 2024
Jan 1, 2025
Jan 1, 2025
Dec 24, 2024

Repository files navigation

telegram_posts_aggregator

Aggregate posts from several channels and send it via bot according the rules.

Diagrams

Overview

ALT TEXT

DB schema

ALT TEXT

Setup environment

Install dependencies

The project uses Poetry for dependency management. Please set up the project following the instructions poetry guide.

Set up Telegram entities

To facilitate a smooth development process, it's recommended to have two Telegram accounts. One can be your primary private account and the other a test account. Due to Telegram's strict rules, it's strongly advised to treat the test account as temporary and be prepared for the possibility of it being permanently banned.

Once you have both accounts set up, proceed to create a Telegram bot via BotFather at https://t.me/BotFather. You can connect the bot with you main account.

After setting up the bot, create two new public channels:

  1. Aggregation channel: This channel should include at least your second account, the bot, and your main account, the bot and the second account should be administrators.
  2. Test channel (source channel): The bot should not be a member of this channel. This channel will serve to simulate a news channel.

Now for your test account you have to create a new application https://my.telegram.org/apps. Keep in mind that telegram can ban this account for no reason GitHub issue

Environment variables

Create a .env file and fill in all required variables (see .env.example, it contains explanation for every field)

Keep in mind that you can't use the same session in multiple applications simultaneously. So it's recommended to create a session for every application (local setup, container setup, etc.)

Run the application in a container

make build
make up-all

Run the application locally

Note: db should be run in a container

make up-local

DB migrations

Create new migration:

alembic revision --autogenerate -m <name>

Upgrade the database to the latest version

alembic upgrade heads

Run unit tests

You can choose any approach to run unit tests. We provide here two of them.
Approach 1 (terminal): run python -m pytest tests in your terminal from the source root.
Approach 2 (PyCharm): read here

Troubleshooting

If you have got Server sent a very new message with ID when initializing the project, try to refresh your session