feat: Telegram QR-Code Invite-Link + WhatsApp Empfang-Fix

Telegram:
- /start <contact_id> Deep-Link Handler: verknüpft Kontakt automatisch mit chat_id
- QR-Code Endpunkt GET /api/v1/contacts/{id}/telegram-qr (PNG)
- TUI: Taste T öffnet QR-Code im Browser (HTML mit eingebettetem PNG)
- config.py + .env.example: TELEGRAM_BOT_USERNAME=mcm_bot
- qrcode[pil] zu requirements.txt hinzugefügt

WhatsApp:
- receiveTimeout 5→3s, HTTP-Timeout 8s → verhindert Polling-Overlap
This commit is contained in:
2026-03-13 14:45:06 +01:00
parent 73619fbc9c
commit 18ad0735ef
9 changed files with 155 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ import logging
from typing import TYPE_CHECKING, Any, Callable, Awaitable
from telegram import Update
from telegram.ext import Application, ApplicationBuilder, MessageHandler, filters
from telegram.ext import Application, ApplicationBuilder, CommandHandler, MessageHandler, filters
from channels.base import BaseChannel
from config import settings
@@ -62,6 +62,7 @@ class TelegramChannel(BaseChannel):
return
self._app = ApplicationBuilder().token(settings.telegram_token).build()
self._app.add_handler(CommandHandler("start", self._handle_start))
self._app.add_handler(MessageHandler(~filters.COMMAND, self._handle_message))
await self._app.initialize()
@@ -97,6 +98,31 @@ class TelegramChannel(BaseChannel):
except Exception as exc:
logger.error("Telegram polling error: %s", exc)
async def _handle_start(self, update: Update, context: Any) -> None:
"""Verarbeitet /start [contact_id] — verknüpft Kontakt mit chat_id."""
if not update.message or not self._inbound_callback:
return
msg = update.message
args = context.args # Liste der Parameter nach /start
contact_id = args[0] if args else None
payload: dict[str, Any] = {
"channel": "telegram",
"channel_message_id": str(msg.message_id),
"sender_telegram_id": str(msg.from_user.id) if msg.from_user else None,
"sender_name": (
(msg.from_user.full_name or msg.from_user.username)
if msg.from_user
else "Unknown"
),
"chat_id": str(msg.chat.id),
"text": "/start",
"reply_to_id": None,
"link_contact_id": contact_id, # Kontakt aus QR-Code verknüpfen
}
await self._inbound_callback(payload)
await msg.reply_text("Willkommen! Sie sind jetzt mit MCM verbunden.")
async def _handle_message(self, update: Update, context: Any) -> None:
if not update.message or not self._inbound_callback:
return

View File

@@ -85,7 +85,8 @@ class WhatsAppChannel(BaseChannel):
return
url = f"{self._base_url}/receiveNotification/{self._token}"
try:
async with self._get_session().get(url, params={"receiveTimeout": 5}) as resp:
timeout = aiohttp.ClientTimeout(total=8)
async with self._get_session().get(url, params={"receiveTimeout": 3}, timeout=timeout) as resp:
if resp.status != 200:
return
data = await resp.json()