diff --git a/back/api/settings.py b/back/api/settings.py index 61bae86..e579ff3 100644 --- a/back/api/settings.py +++ b/back/api/settings.py @@ -27,7 +27,7 @@ SECRET_KEY = "django-insecure-ruo!wst&sb8(f9)j5u4rda-w!673lj_-c0a%gx_t@)ff*q*2ze # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -NGROK_TEMP = "d6af-193-228-134-167.ngrok-free.app" +NGROK_TEMP = "af14-193-228-134-167.ngrok-free.app" ALLOWED_HOSTS = [ "localhost", NGROK_TEMP, diff --git a/back/tgbot/apps.py b/back/tgbot/apps.py index 93aa3cf..6bf2a87 100644 --- a/back/tgbot/apps.py +++ b/back/tgbot/apps.py @@ -26,7 +26,6 @@ class TgBotClass(AppConfig): return app async def some_function(self=None): - print('updater') while True: if not TgBotClass.my_queue.empty(): item = TgBotClass.my_queue.get() @@ -56,4 +55,3 @@ class TgBotClass(AppConfig): thread = threading.Thread(target=TgBotClass.between_callback) thread.setDaemon(True) thread.start() - print(TgBotClass.my_queue) diff --git a/back/tgbot/tgbot.py b/back/tgbot/tgbot.py index dbf0292..c4f27ce 100644 --- a/back/tgbot/tgbot.py +++ b/back/tgbot/tgbot.py @@ -1,11 +1,19 @@ -from asgiref.sync import async_to_sync from django.conf import settings -from telegram import ForceReply, Update -from telegram.ext import Application, CommandHandler, MessageHandler, filters +from telegram import ( + ForceReply, + Update, + ReplyParameters, +) +from telegram.ext import ( + Application, + CommandHandler, + MessageHandler, + filters, + CallbackContext, +) from telegram.constants import ParseMode, ChatType import logging -from .apps import TgBotClass logger = logging.getLogger("root") @@ -13,14 +21,15 @@ logger = logging.getLogger("root") class TgBotApp: _app = None - async def start(self, update, context): + async def start(self, update: Update, context: CallbackContext): user = update.effective_user - logger.info(update) - await update.message.reply_to_message( + # logger.info(update) + await update.message.reply_html( rf"Hi {user.mention_html()}!", - reply_markup={} + # reply_markup=ForceReply(selective=True), + reply_parameters=ReplyParameters(message_id=update.message.message_id), ) - + async def set_webhook(self, url): if not self._app: logger.error("no app") @@ -38,7 +47,7 @@ class TgBotApp: ) self._app.add_handler(CommandHandler("start", self.start)) self._app.add_handler(MessageHandler(filters.ChatType.PRIVATE, self.start)) - + logger.info( { "app": self._app, diff --git a/back/tgbot/views.py b/back/tgbot/views.py index c262989..159651b 100644 --- a/back/tgbot/views.py +++ b/back/tgbot/views.py @@ -24,12 +24,10 @@ class ItemViewSet(viewsets.ViewSet): @async_to_sync async def create(self, request): req = json.loads(request.body) - # logger.info(req) - # logger.info(TgBotClass.app.handlers) update_item = Update.de_json(data=req, bot=TgBotClass.app.bot) - # logger.info(update_item) TgBotClass.my_queue.put(update_item) - logger.info(TgBotClass.my_queue.qsize()) - # await TgBotClass.app.process_update(update_item) + logger.info( + f"Update from {update_item.message.chat.id} pass to que and its size is {TgBotClass.my_queue.qsize()}" + ) return Response({"result": "pass data to tgbot"})