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:
parent
8a84145e15
commit
c30b7e4675
27 changed files with 1155 additions and 280 deletions
|
|
@ -1,4 +1,6 @@
|
|||
from bot.models import ReportType
|
||||
from bot.models import Depth, FocusArea
|
||||
from bot.prompts.depth import DEPTH_CHUNK_MODIFIERS
|
||||
from bot.prompts.focus_areas import FOCUS_CHUNK_BULLETS
|
||||
|
||||
_BASE = """\
|
||||
You are analyzing a batch of Telegram channel posts. Extract structured insights from this chunk.
|
||||
|
|
@ -10,52 +12,11 @@ Posts:
|
|||
{chunk_text}
|
||||
"""
|
||||
|
||||
_CONTENT = """\
|
||||
Focus on:
|
||||
- Main topics and themes discussed
|
||||
- Tone and communication style
|
||||
- Content formats (long-form, short updates, lists, etc.)
|
||||
- Key narratives or recurring ideas
|
||||
- Notable quotes or standout posts
|
||||
|
||||
Provide a concise structured summary."""
|
||||
|
||||
_CONTENT_STATS = """\
|
||||
Focus on:
|
||||
- Main topics and themes discussed
|
||||
- Tone and communication style
|
||||
- Content formats used
|
||||
- Key narratives or recurring ideas
|
||||
- Posting frequency patterns in this batch
|
||||
- Engagement patterns (which topics get more views/forwards/replies)
|
||||
- Any notable spikes or drops in engagement
|
||||
|
||||
Provide a concise structured summary with both qualitative and quantitative observations."""
|
||||
|
||||
_FULL_AUDIT = """\
|
||||
Focus on:
|
||||
- Main topics and themes discussed
|
||||
- Tone and communication style
|
||||
- Content formats used
|
||||
- Key narratives or recurring ideas
|
||||
- Posting frequency patterns
|
||||
- Engagement patterns with specific numbers
|
||||
- Sentiment analysis (positive/negative/neutral distribution)
|
||||
- Audience interaction patterns
|
||||
- Content strengths and weaknesses
|
||||
- Missed opportunities
|
||||
|
||||
Provide a detailed structured summary covering all dimensions."""
|
||||
|
||||
CHUNK_PROMPTS = {
|
||||
ReportType.CONTENT: _CONTENT,
|
||||
ReportType.CONTENT_STATS: _CONTENT_STATS,
|
||||
ReportType.FULL_AUDIT: _FULL_AUDIT,
|
||||
}
|
||||
|
||||
|
||||
def build_chunk_prompt(
|
||||
report_type: ReportType,
|
||||
depth: Depth,
|
||||
focus_areas: list[FocusArea],
|
||||
lang: str,
|
||||
title: str,
|
||||
chunk_text: str,
|
||||
chunk_idx: int,
|
||||
|
|
@ -67,4 +28,14 @@ def build_chunk_prompt(
|
|||
total_chunks=total_chunks,
|
||||
chunk_text=chunk_text,
|
||||
)
|
||||
return base + "\n" + CHUNK_PROMPTS[report_type]
|
||||
parts = [base]
|
||||
|
||||
parts.append(f"Depth: {DEPTH_CHUNK_MODIFIERS[depth]}\n")
|
||||
|
||||
parts.append("Focus on the following areas:")
|
||||
for area in focus_areas:
|
||||
parts.append(FOCUS_CHUNK_BULLETS[area])
|
||||
|
||||
parts.append(f"\nProvide the analysis in {'Russian' if lang == 'ru' else 'English'}.")
|
||||
|
||||
return "\n".join(parts)
|
||||
|
|
|
|||
19
bot/prompts/depth.py
Normal file
19
bot/prompts/depth.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from bot.models import Depth
|
||||
|
||||
DEPTH_CHUNK_MODIFIERS: dict[Depth, str] = {
|
||||
Depth.BASIC: "Provide a brief, high-level summary. Focus on the most important points only. Be concise.",
|
||||
Depth.STANDARD: "Provide a structured summary with moderate detail. Cover key patterns and notable examples.",
|
||||
Depth.FULL: (
|
||||
"Provide an exhaustive, detailed analysis. Include specific examples, quotes, "
|
||||
"numerical data, and subtle patterns. Leave nothing significant out."
|
||||
),
|
||||
}
|
||||
|
||||
DEPTH_SYNTHESIS_MODIFIERS: dict[Depth, str] = {
|
||||
Depth.BASIC: "Keep the report concise and actionable. Use short sections with bullet points.",
|
||||
Depth.STANDARD: "Provide a well-structured report with moderate depth. Balance brevity and detail.",
|
||||
Depth.FULL: (
|
||||
"Produce a comprehensive, in-depth report. Include detailed analysis, specific evidence, "
|
||||
"data-backed observations, and strategic recommendations. Be thorough."
|
||||
),
|
||||
}
|
||||
74
bot/prompts/focus_areas.py
Normal file
74
bot/prompts/focus_areas.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
from bot.models import FocusArea
|
||||
|
||||
FOCUS_CHUNK_BULLETS: dict[FocusArea, str] = {
|
||||
FocusArea.PSYCHOLOGY: (
|
||||
"- Persuasion and influence techniques used\n"
|
||||
"- Cognitive biases leveraged (scarcity, social proof, authority, etc.)\n"
|
||||
"- Emotional triggers and manipulation patterns\n"
|
||||
"- Framing and narrative control techniques"
|
||||
),
|
||||
FocusArea.BUSINESS: (
|
||||
"- Revenue models and monetization strategies\n"
|
||||
"- Product/service placement and promotion patterns\n"
|
||||
"- Conversion funnels and calls-to-action\n"
|
||||
"- Pricing psychology and offer structuring"
|
||||
),
|
||||
FocusArea.MARKETING: (
|
||||
"- Growth tactics and audience acquisition strategies\n"
|
||||
"- Viral mechanics and shareability factors\n"
|
||||
"- Cross-promotion and collaboration patterns\n"
|
||||
"- Brand positioning and differentiation"
|
||||
),
|
||||
FocusArea.CONTENT: (
|
||||
"- Main topics and themes discussed\n"
|
||||
"- Content formats (long-form, short updates, lists, media, etc.)\n"
|
||||
"- Posting frequency and schedule patterns\n"
|
||||
"- Narrative arcs and series/recurring segments\n"
|
||||
"- Content quality and originality assessment"
|
||||
),
|
||||
FocusArea.AUDIENCE: (
|
||||
"- Engagement patterns (views, forwards, replies per content type)\n"
|
||||
"- Audience interaction and community dynamics\n"
|
||||
"- Top-performing vs underperforming content\n"
|
||||
"- Engagement drivers and detractors"
|
||||
),
|
||||
FocusArea.SENTIMENT: (
|
||||
"- Overall sentiment distribution (positive/negative/neutral)\n"
|
||||
"- Sentiment breakdown by topic\n"
|
||||
"- Emotional tone shifts over time\n"
|
||||
"- Controversial or polarizing content identification"
|
||||
),
|
||||
}
|
||||
|
||||
FOCUS_SYNTHESIS_SECTIONS: dict[FocusArea, str] = {
|
||||
FocusArea.PSYCHOLOGY: (
|
||||
"## Psychology & Influence\n"
|
||||
"Analyze persuasion techniques, cognitive biases, emotional triggers, "
|
||||
"and manipulation patterns found across the channel's content."
|
||||
),
|
||||
FocusArea.BUSINESS: (
|
||||
"## Business & Monetization\n"
|
||||
"Detail revenue models, monetization strategies, product placements, "
|
||||
"conversion patterns, and business-related content."
|
||||
),
|
||||
FocusArea.MARKETING: (
|
||||
"## Marketing & Growth\n"
|
||||
"Assess growth tactics, viral mechanics, cross-promotion strategies, "
|
||||
"and brand positioning approaches."
|
||||
),
|
||||
FocusArea.CONTENT: (
|
||||
"## Content Strategy\n"
|
||||
"Analyze topics, formats, posting patterns, narrative arcs, "
|
||||
"content quality, and overall editorial strategy."
|
||||
),
|
||||
FocusArea.AUDIENCE: (
|
||||
"## Audience & Engagement\n"
|
||||
"Deep dive into engagement metrics, audience interaction patterns, "
|
||||
"community dynamics, and what drives or kills engagement."
|
||||
),
|
||||
FocusArea.SENTIMENT: (
|
||||
"## Sentiment Analysis\n"
|
||||
"Present sentiment distribution, emotional tone analysis, "
|
||||
"sentiment by topic, and shifts over time."
|
||||
),
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue