Skip to content

Add Telegram ads simulator for RuneWager campaign optimization#142

Merged
gamblecodezcom merged 1 commit into
mainfrom
claude/telegram-ads-simulator-ONM5x
Mar 7, 2026
Merged

Add Telegram ads simulator for RuneWager campaign optimization#142
gamblecodezcom merged 1 commit into
mainfrom
claude/telegram-ads-simulator-ONM5x

Conversation

@gamblecodezcom
Copy link
Copy Markdown
Owner

@gamblecodezcom gamblecodezcom commented Mar 7, 2026

Summary

Introduces a comprehensive Telegram ads simulator that validates ad creatives for compliance, simulates user behavior across multiple dimensions, and optimizes ad copy through iterative testing. This tool enables data-driven campaign planning for the RuneWager Telegram bot.

Key Changes

  • Ad Validation: Validates 30 ad creatives against Telegram Ads compliance rules (length limits, forbidden words, link validation) with automatic fixes applied where possible
  • Multi-dimensional Simulation: Simulates ad performance across 1,512 combinations of:
    • 6 time-of-day buckets (00:00-24:00)
    • 7 days of the week
    • 6 channel types (crypto signals, casino deals, airdrops, etc.)
    • 6 user personas (bonus hunters, leaderboard grinders, crypto redeemers, etc.)
  • Performance Metrics: Computes CTR, bot start rate, prize redemption rate, leaderboard participation, bonus completion, and ROI index for each combination
  • Bid Sensitivity Analysis: Models how bid adjustments (0.5x, 1.0x, 2.0x) affect impressions, CTR, CPC, and ROI across placement quality tiers
  • Copy Optimization Loop: Runs 3 iterations of ad copy optimization with category-specific wording tweaks, projecting cumulative CTR and conversion improvements
  • Top Ads Selection: Identifies top 3 performing ads using a composite scoring formula (50% ROI + 30% prize redemption + 20% leaderboard participation)
  • Dual Output Format:
    • PART A: Structured JSON with validation results, simulation data, and optimization metrics
    • PART B: Human-readable plain-text summary with actionable insights on best time windows, channels, days, and bid strategies

Notable Implementation Details

  • Uses seeded pseudo-random number generator (LCG) for deterministic, reproducible simulation results
  • Applies dimension-specific multipliers (time, day, channel, persona) to base metrics derived from industry benchmarks
  • Implements category-based ad classification (free code, leaderboard, wager bonus, mixed variants, global, brand) to drive metric selection and optimization tweaks
  • Supports flexible CLI options: --output (file path), --summary-only, --json-only
  • Includes detailed persona definitions and channel type characteristics for transparency in simulation logic

https://claude.ai/code/session_01QSkvVSYsiNQ9udQ3fvVopJ

Summary by Sourcery

Add a CLI Telegram ads simulation script that validates predefined ad creatives, models their performance across multiple audience dimensions, and produces both JSON and human-readable reports, including bid sensitivity and optimization insights for selecting top-performing ads.

New Features:

  • Introduce a Node.js Telegram ads simulator script that validates 30 RuneWager ad creatives for Telegram Ads compliance.
  • Simulate ad performance across time-of-day buckets, days of week, channel types, user personas, and bid levels to generate performance metrics.
  • Provide an automated ad copy optimization loop over three iterations to project metric improvements and refine final ad text.
  • Output both structured JSON data and a plain-text summary report with recommendations on timings, channels, personas, and bidding strategies.

Enhancements:

  • Document personas and channel type characteristics within the simulation output to clarify behavioral and performance assumptions.

Build:

  • Add an executable Node.js script under scripts/ for running simulations via CLI with options for output file and format selection.

Summary by CodeRabbit

  • New Features
    • Telegram ad validation tool that checks compliance for forbidden words, links, and message length constraints.
    • Comprehensive ad simulation across time buckets, days of week, channel types, and user personas.
    • 3-iteration ad optimization with performance metrics and ROI analysis.
    • Top ads selection algorithm.
    • Output options: JSON, human-readable summary, or combined format.

Adds scripts/telegram-ads-simulator.js — a standalone Node.js simulation
engine for RuneWager Telegram Ads campaigns.

Features:
- Validates 30 ad creatives for Telegram Ads compliance (<=160 chars,
  single line, no HTML/Markdown, Telegram links only, forbidden wording check)
- Categorizes ads by dominant appeal: freeCode, leaderboard, wagerBonus,
  global, brand, and mixed variants
- Simulates 45,360 combinations per run (30 ads x 6 time buckets x 7 days
  x 6 channel types x 6 user personas) using seeded LCG PRNG for reproducibility
- Models 6 channel types: HighRollerCasinoChat, CasinoDealsChannel,
  CryptoSignalsChannel, AirdropChannel, GeneralCryptoChat, CasualGamingChannel
- Models 6 personas: BonusHunter, LeaderboardGrinder, CryptoRedeemer,
  CasualTester, NightOwlUS, GlobalGrinder with category affinity boosts
- Bid sensitivity model at 0.5 / 1.0 / 2.0 with placement quality factors
- 3-iteration auto-optimization loop with per-category copy tweaks
- Selects top 3 ads by composite score (50% ROI, 30% prize redemption,
  20% leaderboard participation)
- Outputs PART A machine-readable JSON + PART B plain-text summary
- Supports --output <file>, --summary-only, --json-only flags

Usage:
  node scripts/telegram-ads-simulator.js
  node scripts/telegram-ads-simulator.js --output results/ads-sim.json
  node scripts/telegram-ads-simulator.js --summary-only

https://claude.ai/code/session_01QSkvVSYsiNQ9udQ3fvVopJ
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Mar 7, 2026

Reviewer's Guide

Adds a standalone Node.js CLI script that validates 30 predefined Telegram ad creatives for compliance, deterministically simulates their performance across multiple dimensions, runs a copy-optimization loop, performs bid sensitivity analysis, and outputs both structured JSON and a human-readable summary to stdout or file, with flexible CLI flags.

Sequence diagram for CLI execution and simulation pipeline

sequenceDiagram
  actor User
  participant NodeCLI as Node_cli
  participant Script as telegram_ads_simulator_js
  participant FS as File_system
  participant Stdout
  participant Stderr

  User->>NodeCLI: node scripts/telegram-ads-simulator.js [--output|--summary-only|--json-only]
  NodeCLI->>Script: load and execute main()

  Script->>Stderr: log "Simulator v1.0" and config

  Script->>Script: parse CLI args

  Script->>Script: validateAd() over RAW_ADS
  Script->>Stderr: log validation summary

  Script->>Script: compute total combinations
  Script->>Stderr: log simulation start

  loop for each validated ad (30)
    Script->>Script: runAdSimulation(ad)
    Script->>Script: categorizeAd()
    Script->>Script: simulateCombination() 1,512 times
    Script->>Script: aggregate baseline metrics
    Script->>Script: bidSensitivity()
    Script->>Script: optimizeText() + iterMetrics() for 3 iterations
  end

  Script->>Stderr: log simulation finished

  Script->>Script: selectTopAds(ad_results, validated_ads)
  Script->>Stderr: log top ad IDs

  Script->>Script: build output object
  Script->>Script: JSON.stringify(output)
  Script->>Script: generateSummary(output)

  alt --output provided
    Script->>FS: write JSON + summary to file
    Script->>Stdout: print summary only
  else summary-only
    Script->>Stdout: print summary only
  else json-only
    Script->>Stdout: print JSON only
  else default
    Script->>Stdout: print JSON
    Script->>Stdout: print summary
  end

  Script->>Stderr: log "Simulation complete."
Loading

Class-style diagram for main functions in telegram ads simulator

classDiagram
  class TelegramAdsSimulator {
    +main()
    +validateAd(text, idx)
    +categorizeAd(text)
    +simulateCombination(adId, timeBucket, day, channel, persona, bid)
    +runAdSimulation(validatedAd)
    +bidSensitivity(baselineCTR, baselineCPC, baselineROI)
    +getPersonaMod(persona, category)
    +optimizeText(text, category, iteration)
    +iterMetrics(baseline, iteration)
    +selectTopAds(adResults, validatedAds)
    +generateSummary(output)
  }

  class Config {
    +MAX_LENGTH : number
    +BOT_LINK : string
    +FORBIDDEN_WORDS : string[]
    +TIME_BUCKETS : string[]
    +DAYS_OF_WEEK : string[]
    +CHANNEL_TYPES : string[]
    +PERSONAS : string[]
    +BASE_METRICS : object
    +TIME_MODS : object
    +DAY_MODS : object
    +CHANNEL_MODS : object
    +COPY_TWEAKS : object
  }

  class RNG {
    +lcgRng(seed)
    +hashSeed(adId, timeBucket, day, channel, persona)
  }

  class MetricsUtils {
    +clamp(value, lo, hi)
    +r4(value)
    +r2(value)
    +pct(value)
  }

  class IO {
    +writeFile(outputFile, content)
    +log(msg)
  }

  TelegramAdsSimulator --> Config : uses
  TelegramAdsSimulator --> RNG : uses
  TelegramAdsSimulator --> MetricsUtils : uses
  TelegramAdsSimulator --> IO : uses
Loading

File-Level Changes

Change Details Files
Introduce a deterministic Telegram ads simulation pipeline over predefined creatives with validation, performance modeling, optimization, and reporting.
  • Add raw list of 30 RuneWager Telegram ad creatives and Telegram-specific validation rules including length limits, forbidden words, and link checks with auto-fixing.
  • Implement ad categorization and category-based base performance metrics, plus time-of-day, day-of-week, channel-type, and persona-specific multipliers to compute simulated KPIs per dimension combination.
  • Add seeded LCG-based RNG and hash-derived seeds to provide deterministic per-combination jitter in CTR, conversion rates, CPC, and ROI index calculations.
  • Simulate all 1,512 combinations per ad, aggregate baseline metrics, select top-ROI combinations, and compute bid sensitivity curves for multiple bid levels.
  • Implement a category-driven copy-optimization loop over three iterations with safe text transformations while respecting length/compliance constraints and projecting metric lifts.
  • Select top 3 ads via composite scoring over optimized metrics and compute recommended time windows, channels, and bids per winning ad.
  • Generate a plain-text human-readable summary with tactical recommendations plus a structured JSON payload, and wire up CLI entrypoint options for output file, summary-only, and JSON-only modes.
scripts/telegram-ads-simulator.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b17c64a0-1e79-43ab-8341-3041a7189ec7

📥 Commits

Reviewing files that changed from the base of the PR and between adf783c and e299a01.

📒 Files selected for processing (1)
  • scripts/telegram-ads-simulator.js

📝 Walkthrough

Walkthrough

Introduces telegram-ads-simulator.js, a new script that validates 30 Telegram ad creatives for compliance and runs a multidimensional ad simulation across time buckets, days of week, channel types, and user personas with 3-iteration copy optimization loops, producing JSON output and human-readable summaries.

Changes

Cohort / File(s) Summary
Telegram Ads Simulator
scripts/telegram-ads-simulator.js
New script implementing ad validation (forbidden words, link compliance, length constraints), multidimensional simulation engine (time buckets, days, channels, personas), deterministic seeded RNG, bid sensitivity modeling, and 3-iteration copy optimization with composite scoring for top ad selection.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Script
    participant Validator
    participant Simulator
    participant Optimizer
    participant Ranker
    participant OutputGen

    User->>Script: Run telegram-ads-simulator.js
    Script->>Validator: Validate 30 ads
    Validator->>Validator: Check forbidden words,<br/>link compliance,<br/>length constraints
    Validator-->>Script: Return validated ads
    Script->>Simulator: Configure simulation<br/>(dimensions, metrics, modifiers)
    Script->>Simulator: Run multidimensional<br/>ad simulation
    Simulator->>Simulator: Generate baseline metrics<br/>across all combinations
    Simulator->>Simulator: Compute top-20<br/>ROI combinations
    Simulator-->>Script: Return ad results
    Script->>Optimizer: Run 3-iteration<br/>copy optimization
    Optimizer->>Optimizer: Apply tweaks & lift factors<br/>per iteration
    Optimizer-->>Script: Return optimized versions
    Script->>Ranker: Select top ads<br/>(composite score)
    Ranker-->>Script: Return ranked top 3 ads
    Script->>OutputGen: Generate JSON +<br/>human-readable summary
    OutputGen-->>Script: Return formatted output
    Script-->>User: Output to stdout/file
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested labels

codex, size:XXL

Poem

Whiskers aquiver, a rabbit's delight,
A simulator born to make ads take flight!
Through time buckets, personas, and channels so wide,
Bid optimization becomes our guide,
Three iterations of tweaks and refinement—
Our telegram dreams reach enlightenment! 🐰✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/telegram-ads-simulator-ONM5x

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gamblecodezcom gamblecodezcom merged commit 599565b into main Mar 7, 2026
5 of 6 checks passed
@gamblecodezcom gamblecodezcom deleted the claude/telegram-ads-simulator-ONM5x branch March 7, 2026 06:39
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The CLI argument handling around --output is brittle (e.g., --output as the last arg with no path, or combining --summary-only and --json-only); consider explicitly validating arguments and failing fast with a clear usage message when the combination is invalid.
  • Several values are hard-coded in multiple places (e.g., 30 ads, 10000 impressions, 3 optimization iterations, progress log strings); centralizing these as constants would make future adjustments less error-prone and keep the logs consistent with the simulation config.
  • The selectTopAds aggregation of best time windows currently takes only the first time bucket per channel from the top 5 combinations; if you intend to recommend robust windows, consider aggregating counts and selecting the most frequent/highest-ROI time buckets and days instead of an arbitrary first element.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CLI argument handling around `--output` is brittle (e.g., `--output` as the last arg with no path, or combining `--summary-only` and `--json-only`); consider explicitly validating arguments and failing fast with a clear usage message when the combination is invalid.
- Several values are hard-coded in multiple places (e.g., `30` ads, `10000` impressions, `3` optimization iterations, progress log strings); centralizing these as constants would make future adjustments less error-prone and keep the logs consistent with the simulation config.
- The `selectTopAds` aggregation of best time windows currently takes only the first time bucket per channel from the top 5 combinations; if you intend to recommend robust windows, consider aggregating counts and selecting the most frequent/highest-ROI time buckets and days instead of an arbitrary first element.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants