Notice formatter service

Introduction#

NoticeFormatterService maps categorized notices onto Telegram-ready templates. LLM classification, fuzzy job matching, and per-type layouts without blowing past message length limits.

Project structure#

The Notice Formatter Service resides within the application’s services layer and interacts with data clients, database services, and notification channels through a well-defined dependency injection architecture.

Core components#

The Notice Formatter Service is built around a LangGraph-based state machine that processes notices through distinct stages: text extraction, classification, job matching, enrichment, structured extraction, and final formatting. It maintains a compact set of helper utilities for date formatting, currency display, HTML breakdown parsing, and content prettification.

It can:

  • Multi-stage LLM classification into categories (job posting, shortlisting, webinar, hackathon, announcement, update)
  • Fuzzy company name matching against structured job listings
  • Structured information extraction tailored to each notice category
  • Category-specific formatting templates with consistent Markdown/HTML output
  • Integration hooks for job enrichment callbacks
  • Content cleaning and sanitization for Telegram compatibility

Architecture overview#

Stateful pipeline from messy notice text to a standard message. Add a notice type or channel by extending the maps, not by forking the class.

Detailed component analysis#

NoticeFormatterService class#

The core formatter implements a LangGraph StateGraph with six nodes representing the processing pipeline. Each node encapsulates a specific transformation step with explicit input/output contracts.

Content transformation pipeline#

The pipeline transforms raw HTML content through multiple stages, each with specific responsibilities:

  1. Text Extraction: Converts HTML to plain text while preserving structure
  2. Classification: LLM-driven categorization using strict labeling rules
  3. Job Matching: Entity extraction and fuzzy matching against job listings
  4. Enrichment: Optional detailed job retrieval for matched entries
  5. Structured Extraction: Category-specific JSON parsing with validation
  6. Formatting: Template-based message composition with Telegram compatibility

Category-Specific formatting templates#

The formatter implements distinct templates for each notice type, so consistent presentation across channels:

Job posting template#

  • Header: " Job Posting" with company and role
  • Key Sections: Location, CTC with package breakdown, eligibility criteria, hiring flow
  • Deadlines: Prominent warning with IST formatting
  • Links: Direct job details URL when available

Shortlisting template#

  • Header: " Shortlisting Update"
  • Lists: Total shortlisted count and student names with enrollment numbers
  • Context: Company, role, location, package information
  • Process: Hiring flow steps when available

Webinar template#

  • Header: " Webinar Details"
  • Timing: Flexible date/time formatting with IST timezone
  • Venue: Platform or physical location
  • Registration: Direct link handling with deadline warnings

Hackathon template#

  • Header: " Hackathon"
  • Duration: Start/end date formatting
  • Structure: Theme, team size, prize pool, venue
  • Registration: Deadline and link handling

Announcement template#

  • Header: Bold title with passthrough content
  • Attribution: Author and timestamp footer
  • Minimal Processing: Light cleanup for readability

Integration with telegram message formatting#

The formatter produces content compatible with Telegram’s HTML parsing, with automatic fallback to MarkdownV2 escaping when needed. The Telegram service handles:

  • Character limit enforcement (4000 character chunks)
  • Automatic message splitting with line-aware boundaries
  • Markdown/HTML conversion with special handling for links and headers
  • Retry mechanisms with plain text fallback

Content cleaning and safety features#

The formatter implements detailed content cleaning to ensure safe, readable output:

  • HTML Stripping: BeautifulSoup-based extraction with table parsing and paragraph handling
  • Line Normalization: Collapse excessive blank lines and trim trailing whitespace
  • Special Character Encoding: Proper handling of non-breaking spaces and Unicode characters
  • Link Preservation: Maintains hyperlinks while keeping HTML anchor tags valid
  • Markdown Compatibility: Automatic escaping for Telegram MarkdownV2 special characters

Integration with notification delivery system#

The formatted notices integrate smoothly with the broader notification infrastructure:

Dependency analysis#

The Notice Formatter Service maintains loose coupling with external dependencies through well-defined interfaces and typed data models.

Performance considerations#

The formatter is optimized for production use with several performance-conscious design decisions:

  • Selective Enrichment: Jobs are only enriched when matched during notice processing, avoiding unnecessary API calls
  • Fuzzy Matching Thresholds: Configurable similarity thresholds (80+) prevent false positives while maintaining accuracy
  • State Machine Efficiency: LangGraph minimizes memory overhead through state reuse
  • Batch Processing: Support for formatting multiple notices in sequence
  • Caching Opportunities: Job lookup dictionaries prevent repeated database queries

Troubleshooting guide#

Common issues and their resolutions:

LLM parsing failures#

Symptoms: Empty extracted fields or JSON parsing errors Causes:

  • LLM output format inconsistencies
  • Complex HTML structures causing extraction ambiguity
  • Insufficient context for classification

Resolutions:

  • Verify LLM prompt templates are properly formatted
  • Check HTML content complexity and consider preprocessing
  • Monitor classification confidence scores

Telegram message limits#

Symptoms: Truncated messages or delivery failures Causes:

  • Messages exceeding 4000 characters
  • Improper HTML/Markdown formatting

Resolutions:

  • Enable automatic message splitting in TelegramService
  • Validate message length before sending
  • Test with simplified content first

Job matching issues#

Symptoms: Missed job matches or incorrect fuzzy matches Causes:

  • Company name variations in notices vs. job listings
  • Low similarity threshold settings
  • Missing job enrichment callback

Resolutions:

  • Adjust fuzzy matching thresholds (currently >80)
  • Implement job enrichment callback for matched entries
  • Verify company name normalization

Conclusion#

Classify, extract structure, apply per-category templates aimed at Telegram. Add a notice type by extending the maps, not by forking the service.