Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/studentiunimi/backend
Backend code used by StudentiUniMi to operate its website and Telegram groups.
https://github.com/studentiunimi/backend
django python telegram unimi university
Last synced: about 10 hours ago
JSON representation
Backend code used by StudentiUniMi to operate its website and Telegram groups.
- Host: GitHub
- URL: https://github.com/studentiunimi/backend
- Owner: StudentiUniMi
- License: mit
- Created: 2021-07-25T12:50:52.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-14T10:15:36.000Z (about 2 months ago)
- Last Synced: 2024-09-14T20:47:53.280Z (about 2 months ago)
- Topics: django, python, telegram, unimi, university
- Language: Python
- Homepage: https://api.studentiunimi.it
- Size: 511 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StudentiUniMi backend
## What is this?
This is the official repository for the backend code used by [StudentiUniMi](https://studentiunimi.it)
to operate its website and Telegram groups.
The project is mainly written in Python (>=3.11) and uses [Django](https://www.djangoproject.com) and
[python-telegram-bot](https://python-telegram-bot.readthedocs.io/en/stable/) as helper frameworks.The code is released under MIT license, and the copyright holder is StudentiUniMi.
## Features
### Website API
[Currently](https://github.com/StudentiUniMi/website/tree/master/src/data),
[studentiunimi.it](https://github.com/StudentiUniMi/website) uses a series of .json files as the only data source.
The goal is to completely replace that unreliable system with
a new one supported by a dynamic and more manageable database.
Django is the perfect choice because it's easy, and gives a user-friendly admin interface without too many headaches.We choose to communicate to the frontend with a simple, read-only, JSON, REST API developed with
[django-rest-framework](https://www.django-rest-framework.org/) module.
A model is converted to JSON through a serializer as described
[here](https://www.django-rest-framework.org/api-guide/serializers/) and implemented
[here](https://github.com/StudentiUniMi/backend/blob/master/university/serializers.py).Here's an incomplete list of features:
- [ ] University data API
- [x] Departments
- [x] List API
- [x] Verbose details API
- [x] Representatives
- [ ] Degrees
- [x] List API
- [x] Verbose details API
- [x] Representatives
- [ ] External links
- [x] Degree general Telegram group
- [x] Courses
- [x] List (by degree) API
- [x] Verbose details API
- [x] External links
- [ ] External links
- ...
- ...### Telegram bot
StudentiUniMi has hundreds of Telegram groups, connected with hundreds of courses and
dozens of degrees and departments.
[Currently, it's a mess](https://github.com/StudentiUniMi/website/blob/6253d1d4fd41370b5f668b428d4c1cdad61eb986/src/data/Data.json).The goal is to create a platform to manage Telegram groups.
This includes individual user management, special users (e.g. administrators, professors, representatives, ...),
welcome messages and CAPTCHAs, permissions, moderation (global ban, ban, kick, mute, warn, ...), chat statistics,
information gathering and automated group creation.The [Bot API](https://core.telegram.org/bots/api) has [two ways](https://core.telegram.org/bots/api#getting-updates)
to receive updates: we choose to use [webhooks](https://core.telegram.org/bots/api#setwebhook) because they can work
well with Django.
**TL;DR**: when an event (like a new message) occurs, Telegram will send a POST request to
the already specified endpoint with one (or more) [Update](https://core.telegram.org/bots/api#update) as content.
Django will then process the request with a view (`TelegramBotWebhookView`) that will dispatch the Update with a
[`telegram.ext.Disptacher`](https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.dispatcher.html).For security reasons, every authorized bot will have a different endpoint URL ending with its `?token=XXXXX`.
Before doing any processing, the specified token must match an instance of the `TelegramBot` model.Once again, here's an incomplete list of features:
- [ ] Architecture
- [x] Webhook endpoint
- [x] Ignore request if the bot is not recognized
- [x] Update dispatcher
- [ ] Translations (i18n)- [ ] Information gathering
- [x] Users
- [x] Gather and update general information
- [x] Update sent message count
- [x] Update group membership
- [x] Groups
- [x] Update, if different, chat title
- [x] Periodically update chat photo, description, ...- [ ] Groups
- [ ] Welcome messages
- [x] Greet the user
- [x] Per-group customized welcome message
- [ ] CAPTCHA and rules acceptance for new users
- [x] Moderation
- [x] Auto-ban globally banned users
- [x] Global ban (temporary and permanent)
- [x] Group ban (temporary and permanent)
- [x] Group mute (temporary and permanent)
- [x] Group kick
- [x] Global warn
- [x] Moderation logging
- [x] Info command for administrators
- [x] Special users
- [x] Recognize special users permissions scope
- [x] Automatically set special user permissions and custom titles
- [x] Auto-delete welcome and moderation messages
- [x] Automatic group creation
- ...## Deployment
We use Docker Swarm to deploy this project on our systems. Tune your settings by editing `.env` and
`docker-compose.yml` files, then run `./deploy.sh`.
It's highly recommended using a reverse proxy to run the application in production, like
[Traefik](https://github.com/traefik/traefik).You can use the automatically updated
[`ghcr.io/studentiunimi/backend:latest`](https://github.com/StudentiUniMi/backend/pkgs/container/backend)
Docker image if you want the latest version available on the master branch.