Add multi-user features: i18n, payments, multi-model AI, focus areas

Replace single report type with composable analysis: depth levels
(basic/standard/full) + focus area multi-select (psychology, business,
marketing, content, audience, sentiment). Multi-step inline keyboard
flow guides users through selection.

- i18n: English + Russian, auto-detect from Telegram, /lang override
- AI providers: Anthropic + OpenRouter via AIClient abstraction
- Telegram Stars payments with per-depth pricing and free trial
- SQLite (aiosqlite) for users, analyses, payments tracking
- User middleware for auto-registration and language detection
- Report persistence: save .md locally, offer file download
- New commands: /features, /prices, /lang
- Composable prompt system: depth modifiers + focus area fragments
This commit is contained in:
Sergei Poljanski 2026-02-23 01:18:12 +02:00
commit c30b7e4675
27 changed files with 1155 additions and 280 deletions

View file

@ -1,4 +1,6 @@
from bot.models import ReportType
from bot.models import Depth, FocusArea
from bot.prompts.depth import DEPTH_SYNTHESIS_MODIFIERS
from bot.prompts.focus_areas import FOCUS_SYNTHESIS_SECTIONS
_BASE = """\
You are producing a final report for a Telegram channel analysis.
@ -13,103 +15,11 @@ Below are the summaries from each chunk of the channel's history:
{chunk_summaries}
"""
_CONTENT = """\
Synthesize the chunk summaries into a comprehensive **Content Analysis Report** with these sections:
## Overview
Brief channel description and positioning.
## Key Topics & Themes
Main subject areas with examples.
## Tone & Communication Style
How the channel communicates with its audience.
## Content Strategy
Formats used, posting patterns, narrative arcs.
## Notable Content
Standout posts or recurring motifs.
## Summary
Key takeaways in 3-5 bullet points.
Use Telegram-friendly formatting (bold, bullet points). Be specific reference actual content patterns you observed."""
_CONTENT_STATS = """\
Synthesize the chunk summaries into a comprehensive **Content & Stats Report** with these sections:
## Overview
Brief channel description, subscriber count, and overall activity level.
## Key Topics & Themes
Main subject areas ranked by frequency and engagement.
## Tone & Communication Style
How the channel communicates with its audience.
## Content Strategy
Formats used, posting patterns, narrative arcs.
## Engagement Analysis
- Average engagement patterns
- Top-performing content types
- Engagement trends over time
## Posting Patterns
Frequency, schedule consistency, any notable gaps or bursts.
## Summary
Key takeaways in 5-7 bullet points mixing qualitative and quantitative insights.
Use Telegram-friendly formatting. Include specific numbers where available."""
_FULL_AUDIT = """\
Synthesize the chunk summaries into a comprehensive **Full Channel Audit** with these sections:
## Executive Summary
Channel positioning, key metrics, and overall assessment.
## Key Topics & Themes
Main subject areas ranked by frequency and engagement, with trend analysis.
## Tone & Communication Style
Detailed analysis of voice, register, and audience relationship.
## Content Strategy Assessment
Formats, patterns, narrative arcs what works and what doesn't.
## Engagement Deep Dive
- Engagement metrics and benchmarks
- Top-performing vs underperforming content
- Engagement drivers and detractors
## Sentiment Analysis
Overall sentiment distribution, sentiment by topic, shifts over time.
## Audience Insights
Inferred audience profile, interaction patterns, community dynamics.
## Strengths
What the channel does well (3-5 points with evidence).
## Areas for Improvement
Actionable recommendations (3-5 points with specific suggestions).
## Strategic Recommendations
Forward-looking advice for channel growth and content optimization.
Use Telegram-friendly formatting. Be specific back every claim with observed patterns or data."""
SYNTHESIS_PROMPTS = {
ReportType.CONTENT: _CONTENT,
ReportType.CONTENT_STATS: _CONTENT_STATS,
ReportType.FULL_AUDIT: _FULL_AUDIT,
}
def build_synthesis_prompt(
report_type: ReportType,
depth: Depth,
focus_areas: list[FocusArea],
lang: str,
title: str,
username: str | None,
subscribers: int | None,
@ -127,4 +37,18 @@ def build_synthesis_prompt(
chunk_count=len(chunk_summaries),
chunk_summaries=numbered,
)
return base + "\n" + SYNTHESIS_PROMPTS[report_type]
parts = [base]
parts.append("Synthesize the chunk summaries into a comprehensive report with these sections:\n")
parts.append("## Overview\nBrief channel description and positioning.\n")
for area in focus_areas:
parts.append(FOCUS_SYNTHESIS_SECTIONS[area] + "\n")
parts.append("## Key Takeaways\nSummarize the most important findings.\n")
parts.append(DEPTH_SYNTHESIS_MODIFIERS[depth])
parts.append(f"\nWrite the entire report in {'Russian' if lang == 'ru' else 'English'}.")
parts.append("Use Telegram-friendly formatting (bold, bullet points). Be specific — reference actual content patterns.")
return "\n".join(parts)