Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Running python-telegram-bot in Django environment#4655

Unanswered
mattaliev asked this question inQ&A
Discussion options

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?

You must be logged in to vote

Replies: 1 comment

Comment options

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

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@mattaliev@Poolitzer

[8]ページ先頭

©2009-2025 Movatter.jp