que tg
This commit is contained in:
parent
639857b310
commit
2750cea9c4
|
@ -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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
NGROK_TEMP = "d6af-193-228-134-167.ngrok-free.app"
|
NGROK_TEMP = "af14-193-228-134-167.ngrok-free.app"
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
"localhost",
|
"localhost",
|
||||||
NGROK_TEMP,
|
NGROK_TEMP,
|
||||||
|
|
|
@ -26,7 +26,6 @@ class TgBotClass(AppConfig):
|
||||||
return app
|
return app
|
||||||
|
|
||||||
async def some_function(self=None):
|
async def some_function(self=None):
|
||||||
print('updater')
|
|
||||||
while True:
|
while True:
|
||||||
if not TgBotClass.my_queue.empty():
|
if not TgBotClass.my_queue.empty():
|
||||||
item = TgBotClass.my_queue.get()
|
item = TgBotClass.my_queue.get()
|
||||||
|
@ -56,4 +55,3 @@ class TgBotClass(AppConfig):
|
||||||
thread = threading.Thread(target=TgBotClass.between_callback)
|
thread = threading.Thread(target=TgBotClass.between_callback)
|
||||||
thread.setDaemon(True)
|
thread.setDaemon(True)
|
||||||
thread.start()
|
thread.start()
|
||||||
print(TgBotClass.my_queue)
|
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
from asgiref.sync import async_to_sync
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from telegram import ForceReply, Update
|
from telegram import (
|
||||||
from telegram.ext import Application, CommandHandler, MessageHandler, filters
|
ForceReply,
|
||||||
|
Update,
|
||||||
|
ReplyParameters,
|
||||||
|
)
|
||||||
|
from telegram.ext import (
|
||||||
|
Application,
|
||||||
|
CommandHandler,
|
||||||
|
MessageHandler,
|
||||||
|
filters,
|
||||||
|
CallbackContext,
|
||||||
|
)
|
||||||
from telegram.constants import ParseMode, ChatType
|
from telegram.constants import ParseMode, ChatType
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from .apps import TgBotClass
|
|
||||||
|
|
||||||
logger = logging.getLogger("root")
|
logger = logging.getLogger("root")
|
||||||
|
|
||||||
|
@ -13,12 +21,13 @@ logger = logging.getLogger("root")
|
||||||
class TgBotApp:
|
class TgBotApp:
|
||||||
_app = None
|
_app = None
|
||||||
|
|
||||||
async def start(self, update, context):
|
async def start(self, update: Update, context: CallbackContext):
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
logger.info(update)
|
# logger.info(update)
|
||||||
await update.message.reply_to_message(
|
await update.message.reply_html(
|
||||||
rf"Hi {user.mention_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):
|
async def set_webhook(self, url):
|
||||||
|
|
|
@ -24,12 +24,10 @@ class ItemViewSet(viewsets.ViewSet):
|
||||||
@async_to_sync
|
@async_to_sync
|
||||||
async def create(self, request):
|
async def create(self, request):
|
||||||
req = json.loads(request.body)
|
req = json.loads(request.body)
|
||||||
# logger.info(req)
|
|
||||||
# logger.info(TgBotClass.app.handlers)
|
|
||||||
update_item = Update.de_json(data=req, bot=TgBotClass.app.bot)
|
update_item = Update.de_json(data=req, bot=TgBotClass.app.bot)
|
||||||
# logger.info(update_item)
|
|
||||||
TgBotClass.my_queue.put(update_item)
|
TgBotClass.my_queue.put(update_item)
|
||||||
logger.info(TgBotClass.my_queue.qsize())
|
logger.info(
|
||||||
# await TgBotClass.app.process_update(update_item)
|
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"})
|
return Response({"result": "pass data to tgbot"})
|
||||||
|
|
Loading…
Reference in New Issue