Comments (8)
PTB v20.0 was released a few days ago!
Although I think we should wait for Django 4.2, since it'll contain lots of useful async ORM methods (.asave(), .aadd(), .aget(), full list of model changes here), which, as @SergSm said, will decrease the amount of ugly hacks.
It's expected April 2023, so 3 months from now.
from django-telegram-bot.
It's great question!
Just one hour ago i took template and set it to pre-release version 20.0a2
The main problem is to rewrite tgbot/dispatcher.py
to application instance, using Application.builder()
Updating items in database using Models need s@sync_to_async
decorator to be set in tgbot/models.py
I'm not Professional python developer, but it was a great and not such difficult experience
So, you can try!
P.S. yep, it's fully async, so handlers need to be async/awaited
from django-telegram-bot.
To make this work we need to wait at least django 4.2 to be released since Django ORM is still only sync. Also the new PTB 20 has new backward incompatible syntax and still not have a stable release
from django-telegram-bot.
It's great question! Just one hour ago i took template and set it to pre-release version 20.0a2
The main problem is to rewrite
tgbot/dispatcher.py
to application instance, usingApplication.builder()
Updating items in database using Models need s@sync_to_async
decorator to be set intgbot/models.py
I'm not Professional python developer, but it was a great and not such difficult experience So, you can try!
P.S. yep, it's fully async, so handlers need to be async/awaited
Thanks for your answer!
Could you show the code?
I added django.setup()
in my bot to access django and rewrote all the code related to database in an async way
https://gist.github.com/SergSm/68783e59720afdd57114a179fdd835ab
It works somehow but I think that I misunderstand something and I donβt have to run bot in a separate webserver process.
Is there another way to trigger bot without need for running a separate webserver process?
from django-telegram-bot.
I found the way to serve external requests by running uvicorn programatically in the same async context like that:
async with application_tg:
await application_tg.start()
await server.serve() # uvicorn
await application_tg.stop()
In addition to the said above:
I can't access python-telegram-bot Application() instance from views.py
because it is inside of main() function.
I tried to use global
keyword but without any results:
https://gist.github.com/SergSm/6843fadf505b826f83a10bf7eebc3fa0
from django-telegram-bot.
Please make PR with ideas! Should be useful for the community
from django-telegram-bot.
Maybe..
I managed to make it work in a some perverted way but we should definitely wait for a stable PTB release.
Django 4.2 is not a must have but it will decrease a number of some ugly hacks related to a database
from django-telegram-bot.
Any news about updating to PTB and Django 4.2 or 5 versions?
from django-telegram-bot.
Related Issues (20)
- get user's profile photos HOT 2
- add Amplitude integration
- Add typing to functions
- Add tests
- add integration with Metabase (link to @olhd instruciton in readme + screenshots)
- release and tag "v2.0" on github main page
- TypeError with arbitrary callback_data HOT 1
- Make migrations folder persistent HOT 1
- Add global handler for handling all errors
- Webhook does not work HOT 1
- Add Poetry integration
- Demo bot is not working HOT 6
- 'backports.zoneinfo.ZoneInfo' object has no attribute 'normalize' HOT 1
- WARNINGS: tgbot.Location: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- License doesn't contain licensor details
- 404 Error when accessing admin panel page on http://localhost:8000/tgadmin/ HOT 1
- Adding linux-utils on deploy HOT 2
- No hook sender verification
- Question: Long polling vs webhooks in docker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-telegram-bot.