- Notifications
You must be signed in to change notification settings - Fork5.7k
-
Hello! I have been using this library with a couple of my django projects and I have been really enjoying it. My django projects are all running on uWSGI, so I have been using the last synchronous version of this library which is v13.15. Django wasn't just handling Telegram updates, it was handling the whole mini app backend logic as well. So, It was simpler for me just to create a single view responsible for Telegram updates. Here is what my set up looked like # dispatcher.pyfromtelegramimportBotfromtelegram.extimportCommandHandler,Dispatcher,ConversationHandler,MessageHandler,Filtersfromdjango.confimportsettingsfrom .handlersimportstart_handler,set_url_handler,receive_url_handler,cancel_handlerRECEIVE_URL=0bot=Bot(token=settings.TELEGRAM_BOT_TOKEN)dispatcher=Dispatcher(bot,None,use_context=True)dispatcher.add_handler(CommandHandler('start',start_handler))ifsettings.DEBUG:conv_handler=ConversationHandler(entry_points=[CommandHandler('set_url',set_url_handler)],states={RECEIVE_URL: [MessageHandler(Filters.text,receive_url_handler)], },fallbacks=[CommandHandler('cancel',cancel_handler)], )dispatcher.add_handler(conv_handler) # view.pyimportjsonfromrest_frameworkimportstatus,permissionsfromrest_framework.responseimportResponsefromrest_framework.viewsimportAPIViewfromtelegramimportUpdatefrom .dispatcherimportdispatcher,botclassTelegramBotWebhookView(APIView):permission_classes= [permissions.AllowAny]defpost(self,request):update=Update.de_json(json.loads(request.body),bot)dispatcher.process_update(update)returnResponse({'success':True},status=status.HTTP_200_OK) Now, I find myself in the position where I want to integrate new Telegram features in my application and for that I need the latest version of this library. But, a lot has changed since the version that I am and now the whole library is async and I haven't been able to set it up the same yet. I even changed my django project to run ASGI with daphne instead of uWSGI, but still having some troubles. Is it still possible to set up this version in a similar way that I had before? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi yes I would be surprised if you can't get it working very similarly to how it is in the synchronous version, we didn't fundamentally change how the library processes updates, just moved code around to make it more logical/async friendly. We have a customwebhook example, with uvicorn but I am sure you can also get the same with solely django.https://docs.python-telegram-bot.org/en/stable/examples.customwebhookbot.html |
BetaWas this translation helpful?Give feedback.