Initial MCM project: FastAPI + Textual TUI unified messenger
MultiCustomerMessenger supporting Telegram (python-telegram-bot), WhatsApp (Green API) and SMS (python-gsmmodem-new). REST API with Bearer-token auth, SQLAlchemy models for MariaDB, APScheduler for background polling, and Textual TUI running in same asyncio event-loop.
This commit is contained in:
0
tasks/__init__.py
Normal file
0
tasks/__init__.py
Normal file
39
tasks/receiver.py
Normal file
39
tasks/receiver.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.triggers.interval import IntervalTrigger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from channels.whatsapp_channel import WhatsAppChannel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_scheduler: AsyncIOScheduler | None = None
|
||||
_whatsapp: "WhatsAppChannel | None" = None
|
||||
|
||||
|
||||
def build_scheduler(whatsapp: "WhatsAppChannel") -> AsyncIOScheduler:
|
||||
global _scheduler, _whatsapp
|
||||
_whatsapp = whatsapp
|
||||
|
||||
_scheduler = AsyncIOScheduler(timezone="UTC")
|
||||
|
||||
# WhatsApp-Polling alle 5 Sekunden
|
||||
_scheduler.add_job(
|
||||
_poll_whatsapp,
|
||||
trigger=IntervalTrigger(seconds=5),
|
||||
id="whatsapp-poll",
|
||||
name="WhatsApp incoming messages",
|
||||
max_instances=1,
|
||||
coalesce=True,
|
||||
)
|
||||
|
||||
return _scheduler
|
||||
|
||||
|
||||
async def _poll_whatsapp() -> None:
|
||||
if _whatsapp:
|
||||
await _whatsapp.poll_incoming()
|
||||
Reference in New Issue
Block a user