Jump to content

User:NellieBly Bot/technology

From Meta, a Wikimedia project coordination wiki

NellyBly bot runs the Blybot codebase.

[edit]

Runtime stack

[edit]
Layer Technology
Language Python 3.11 or newer; Toolforge deployment uses Python 3.13 image.
Telegram python-telegram-bot async handlers and rate limiter.
Wiki publishing Direct async httpx client for the MediaWiki Action API.
Storage Toolforge ToolsDB / MariaDB via PyMySQL.
Encryption cryptography Fernet for group-supplied GitHub tokens.
GitHub GitHub REST API for issues, repository summaries, and polling repository events.
LLM analyses Wikimedia LiftWing OpenAI-compatible endpoint with Qwen model aliases.
Deployment Wikimedia Toolforge continuous job.
Build/test tooling uv, Hatchling, Ruff, mypy strict mode, pytest.

Architecture

[edit]

The repository uses a ports-and-adapters structure:

  • src/blybot/domain/ — immutable value objects, sanitizer, rendering, prompt contracts, pseudonym generation, and Protocol definitions. This layer has no I/O dependencies.
  • src/blybot/services/ — use cases: publish, transcribe, capture, analysis, rules, scheduling, repo notifications, feedback, directory/profile resolution.
  • src/blybot/adapters/ — external systems: Telegram, MediaWiki, GitHub, LiftWing, ToolsDB, system clock.
  • src/blybot/__main__.py — composition root that wires the object graph and starts polling.

The test suite includes architecture checks so dependency arrows stay inward: adapters use services, services use domain ports, and domain does not import I/O libraries.

Telegram integration

[edit]

The bot uses long polling, so no public webhook endpoint is required.

Normal deployments request only:

  • message;
  • my_chat_member;
  • chat_member.

Capture-enabled deployments also subscribe to channel posts and group messages, and require Telegram privacy mode off. Capture itself remains opt-in per group/topic/channel.

MediaWiki publishing

[edit]

The MediaWiki adapter uses:

  • BotPassword login;
  • CSRF token handling;
  • assert=user on edits and uploads;
  • maxlag=5 with bounded backoff;
  • descriptive configured User-Agent;
  • section=new for new discussions;
  • section lookup plus appendtext for continuing DM sessions;
  • direct file upload for /logmedia.

User-supplied text is sanitized before any wiki write.

Sanitization

[edit]

Blybot uses character-level wikitext neutralization rather than only wrapping text in <nowiki>. It encodes characters that can alter page structure, including braces, brackets, pipes, equals signs, tildes, raw HTML brackets, quotes, and line-leading wiki syntax.

This prevents selected Telegram text from:

  • transcluding templates;
  • adding categories;
  • creating headings;
  • signing as a wiki user;
  • creating tables or parser-extension markup;
  • breaking out into separate wiki structure.

Pseudonyms

[edit]

Normal pseudonyms are generated with Python's secrets module. The pseudonym factory takes no Telegram identifier as input.

Capture pseudonyms are HMAC-SHA256 labels scoped to chat and topic. They are stable only within that scope and are stored instead of Telegram usernames, display names, or user IDs.

Storage model

[edit]

The main ToolsDB table is profiles. It stores group/topic configuration, including selected wiki page, consent policy, bound repository, encrypted token presence, event rules, poll cursors, LLM settings, scheduled actions, and capture state.

Capture-enabled deployments also create a messages table. It stores captured text and metadata for opted-in scopes only: chat_id, thread_id, message_id, posted_at, pseudonym author label, message kind, text, and reply-to ID.

Secrets live in a Toolforge env file with permissions 0600, not in the repository.

GitHub integration

[edit]

There are two GitHub paths:

  • Operator bug reports: private /bug files an anonymous issue on the maintainer's configured tracker if GITHUB_TOKEN is set.
  • Group repositories: admins bind owner/repo with /setrepo, then privately provide a fine-grained PAT restricted to that repository with Issues read/write. The token is encrypted before storage.

Repository notifications are polling-based. Rules decide which GitHub events are delivered live or as digests.

LLM analysis design

[edit]

Analysis uses captured archive windows. The model does not write wikitext or choose destinations.

Safety layers include:

  • transcript data fenced with random per-request markers;
  • chat-template control token scrubbing;
  • JSON-array output contract;
  • retry once on malformed model output;
  • publish-nothing behavior on truncation or contract failure;
  • sanitizer applied to every model-written string before wiki publication.

Default model alias: llm-qwen3-14b. Large model alias: llm-qwen36-27b. Operators can repoint aliases in deployment config.

Operations

[edit]

Typical Toolforge job:

toolforge jobs run blybot --command ./run.sh --image python3.13 --continuous --mem 768Mi

The repository includes deploy-instance.sh for running multiple instances from one checkout, each with its own Telegram bot token, config file, and Toolforge job.

Development checks

[edit]

The project expects:

make install
make hooks
make check

The quality gates include Ruff lint/format, mypy strict mode, pytest, warnings-as-errors, and 100% branch coverage.