bot = BaseTelegramBot(bot_data=bot_data)
bot_thread = threading.Thread(target=bot.run_bot)
bot_thread.start()
class BaseTelegramBot:
def __init__(self, bot_data):
super().__init__()
self.bot = Bot(token=self.token)
self.dispatcher = Dispatcher()
def run_bot(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.start())
loop.close()
async def start(self):
await self.dispatcher.start_polling(self.bot)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.submit(bot.start)
FROM python:3.12-slim
ENV POETRY_VERSION=1.8.2
ENV POETRY_HOME=/opt/poetry
ENV POETRY_VIRTUALENVS_CREATE=false
ENV PATH="$POETRY_HOME/bin:$PATH"
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
RUN apt-get update && apt-get install --no-install-recommends -y curl \
&& curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION} \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install --no-install-recommends -y build-essential \
&& poetry install --no-root --only main \
&& apt-get purge --auto-remove -y build-essential \
&& rm -rf /var/lib/apt/lists/*
CMD ["python", "db.py"]
CMD ["python", "test_data.py"]
CMD ["uvicorn", "api:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]