simplified post creation via telegram

This commit is contained in:
2026-02-19 20:32:22 +01:00
parent 0163767171
commit c7cdebcd5d

View File

@@ -359,7 +359,7 @@ class TelegramService:
async def _handle_post_type_selected( async def _handle_post_type_selected(
self, chat_id: str, user_id: str, post_type_id_str: str, conv: dict, message_id: int, db self, chat_id: str, user_id: str, post_type_id_str: str, conv: dict, message_id: int, db
) -> None: ) -> None:
"""Generate a post after the user selects a post type.""" """Generate a post after the user selects a post type (Writer-only, no critic loop)."""
topic_text = conv.get("topic", "") topic_text = conv.get("topic", "")
if not topic_text: if not topic_text:
await self.send_message(chat_id, "❌ Kein Thema gefunden. Bitte starte von vorne.") await self.send_message(chat_id, "❌ Kein Thema gefunden. Bitte starte von vorne.")
@@ -374,29 +374,72 @@ class TelegramService:
return return
# Edit the post-type selection message to show progress # Edit the post-type selection message to show progress
await self.edit_message(chat_id, message_id, "⏳ Erstelle deinen Post... Das kann einen Moment dauern.") await self.edit_message(chat_id, message_id, "⏳ Erstelle deinen Post...")
try: try:
from src.orchestrator import orchestrator user_uuid = UUID(user_id)
result = await orchestrator.create_post(
user_id=UUID(user_id), # Load everything the writer needs
topic={"title": topic_text, "description": topic_text}, post_type = await db.get_post_type(UUID(post_type_id_str))
post_type_id=UUID(post_type_id_str), if not post_type:
max_iterations=2 # Fewer iterations for faster Telegram response await self.send_message(chat_id, "❌ Post-Typ nicht gefunden.")
return
profile_analysis = await db.get_profile_analysis(user_uuid)
if not profile_analysis:
await self.send_message(chat_id, "❌ Profil-Analyse nicht gefunden. Bitte richte zuerst deinen Account in der App ein.")
return
# Style examples — prefer type-specific, fall back to all
linkedin_posts = await db.get_posts_by_type(user_uuid, UUID(post_type_id_str))
if len(linkedin_posts) < 3:
linkedin_posts = await db.get_linkedin_posts(user_uuid)
example_post_texts = [
p.post_text for p in linkedin_posts
if p.post_text and len(p.post_text) > 100
][:10]
# Company strategy if available
company_strategy = None
profile = await db.get_profile(user_uuid)
if profile and profile.company_id:
company = await db.get_company(profile.company_id)
if company and company.company_strategy:
company_strategy = company.company_strategy
# Single writer pass — no critic loop
from src.agents.writer import WriterAgent
writer = WriterAgent()
post_content = await writer.process(
topic={"title": topic_text, "fact": topic_text, "relevance": "User-specified topic"},
profile_analysis=profile_analysis.full_analysis,
example_posts=example_post_texts,
post_type=post_type,
user_thoughts=topic_text,
company_strategy=company_strategy,
strategy_weight=post_type.strategy_weight,
) )
post_content = result.get("final_post", "") # Save the post to DB (status=draft, no critic data)
post_id = str(result.get("post_id", "")) from src.database.models import GeneratedPost
saved = await db.save_generated_post(GeneratedPost(
user_id=user_uuid,
topic_title=topic_text[:200],
post_content=post_content,
iterations=1,
writer_versions=[post_content],
status="draft",
post_type_id=UUID(post_type_id_str),
))
# Update conversation state # Update conversation state
new_conv = { await self._set_conv(chat_id, {
"state": "waiting_feedback", "state": "waiting_feedback",
"user_id": user_id, "user_id": user_id,
"topic": topic_text, "topic": topic_text,
"post_id": post_id, "post_id": str(saved.id),
"post_content": post_content "post_content": post_content,
} })
await self._set_conv(chat_id, new_conv)
await self.send_message( await self.send_message(
chat_id, chat_id,