
Will run your bot while you will be able to import Django Models and work with them inside that script.This application helps you to integrate your existing Django application with Slack. $ DJANGO_SETTINGS_MODULE=ttings telegram_bot.py So, create a separate Python script (for example, telegram_bot.py in the root of your app) for running your Telegram bot and run it separately. All you need to do is to specify DJANGO_SETTINGS_MODULE environment variable to help Django find your settings module. If so, you can still access django from your other scripts. I understand that you're likely seeking for a way to get data from Django ORM inside the Telegram bot or use some other Django features. Different configurations of the web server in different environments will make it harder to write the correct and scalable code for serving both a web app and a Telegram bot. Moreover, now you are using Django Development server using manage.py command, but if you're going to deploy your application to production environment, your configuration will differ: you should use some production-ready solution like gunicorn. Django runs the code synchronously and it means that even if you succeed in running Telegram bot code, it will hang web application server because of infinite loop in Telegram bot handler.Django runs more than one worker and your telegram bot library does not seem to support running parallel workers.The problem here is that you're trying to run telegram handler loop inside a Djnago application. """Send a message when the command /start is issued."""ĭispatcher.add_handler(CommandHandler("start", start))Īctually, the best solution here is to split Telegram bot and web application to use different processes (run it separately). from telegram import Update, ForceReplyįrom telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContextĭef start(update: Update, context: CallbackContext) -> None: : Conflict: terminated by other getUpdates request make sure that only one bot instance is runningĪnd this the code of telegramBot.py file. I got this error message evrytime I run the project I added this code to the apps.py file of one the project's app but it's not working. from django.apps import AppConfigĭefault_auto_field = 'django.db.models.BigAutoField' I'm using python-telegram-bot but do not know how to start the bot when the django server starts. I'm developing a djnago project and want to connect a telegram bot to it.
