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!
|
||||
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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"})
|
||||
|
|
Loading…
Reference in New Issue