Skip to main content

sase-telegram — Telegram Integration Chop for sase

PyPI Ruff mypy pytest

Overview

sase-telegram is a plugin for sase that provides two-way Telegram integration. It sends SASE notifications to Telegram, and lets you respond to plan approvals, HITL requests, user questions, and even launch new agents — all from Telegram.

Installation

For a managed SASE install, install sase-telegram into the same uv tool environment as sase so its CLI scripts are available to SASE's chop automation.

Recommended: SASE Admin Center Updates tab

If SASE is already installed with uv tool install sase, open sase ace, press # for the SASE Admin Center, then go to the Updates tab (5, or [ / ]). Highlight sase-telegram in the plugin list (j / k, or / to filter), press i to install, and confirm the preview modal. The preview shows the exact uv command and resolved package set; the install runs as a tracked background task and is discovered on the next sase run.

See the core SASE docs for the Updates tab and sase plugin commands.

Alternative: install SASE and the plugin together

uv tool install sase --with sase-telegram

Repeat --with for additional plugins, for example --with sase-telegram --with sase-github. Add --force to replace an existing tool install.

Equivalent CLI for an existing install

sase plugin install telegram

pip install sase-telegram is only an escape hatch for non-managed or library-style environments. It is not the normal path for a uv tool-managed SASE command.

Requires sase>=0.1.0 as a dependency (installed automatically).

What's Included

CLI Scripts

Installing sase-telegram adds the following commands:

Command Description
sase_chop_tg_outbound Send pending notifications to Telegram (supports --dry-run)
sase_chop_tg_inbound Poll Telegram for user responses and process them

Supported Notification Types

Type Telegram Behavior
Plan Approval Shows plan content with Tale / ✅ Approve / Epic / Legend / Reject / Feedback buttons
HITL Request Shows request notes with Accept / Reject / Feedback buttons
User Question Shows question with dynamic option buttons + Custom input
Workflow Complete Sends a summary message with diff/chat attachments and a Fork copy button
Agent Launched Shows provider/model label, workspace number, prompt snippet, and Fork / Wait / Kill / Retry buttons
Agent Killed Confirms termination with a Redo copy button to re-launch with the same prompt
Error Digest Sends error summary with digest file attachments
Image Generated Sends model name and generated image inline

Features

  • Outbound notifications — sends unread, non-silent SASE notifications to Telegram
  • Rate limiting — sliding-window rate limiter prevents message flooding
  • Exclusive outbound locking — prevents concurrent outbound runs from duplicating sends
  • Two-step feedback — press a Feedback/Custom button, then type your response
  • Agent launching — send a text message to spawn a new sase agent from Telegram
  • Auto-naming — agents launched from Telegram automatically get assigned names
  • xprompt expansion — agent prompts expand xprompt references (e.g. #mentor)
  • Multi-model directives — use %{%m:opus | %m:sonnet} to launch the same prompt across multiple models
  • Copy-text buttons — Fork, Wait, Retry, Redo, plan, and ChangeSpec buttons copy pre-filled text to your clipboard
  • Photo/document handling — send photos, albums, or image documents to launch agents with visual context
  • Slash commands/list, /kill [<name>], /fork, /changes [project], /xprompts, /bead [<id>], /update for agent management, ChangeSpec, xprompt, bead, and SASE update workflows from Telegram (registered with set_my_commands so they show up in the chat input UI)
  • PDF attachments — Markdown attachments are rendered to PDF through the shared SASE renderer when possible
  • Large content handling — auto-truncates long plans and notes; uses expandable blockquotes for medium content
  • Message splitting — messages exceeding Telegram's 4096-character limit are automatically split
  • Parse mode fallback — falls back to plain text if MarkdownV2 rendering fails

Configuration

Machine Enable Flag

The chops are no-ops unless ~/.sase/telegram_is_enabled exists. When the flag file is absent, sase_chop_tg_outbound and sase_chop_tg_inbound exit immediately with status 0, print nothing, and skip all heavy imports, network calls, and locks. This lets the telegram lumberjack be configured globally (on every machine) while only explicitly-enabled machines actually talk to Telegram.

Enable a machine with:

touch ~/.sase/telegram_is_enabled

Credentials

Bot token sources are checked in order:

Source Description
SASE_TELEGRAM_BOT_TOKEN Bot token from the environment
~/.sase/telegram_bot_token Bot token file; must not be group/other-readable
pass show telegram_sase_bot_token Bot token from pass

The chat target and bot username are required separately:

Source Description
SASE_TELEGRAM_BOT_CHAT_ID Chat ID to send messages to
SASE_TELEGRAM_BOT_USERNAME Bot username

Environment Variables

Variable Default Description
SASE_TELEGRAM_RATE_LIMIT 8/15 Rate limit as max_messages/window_seconds
SASE_TELEGRAM_LAUNCH_AGENTS_DISABLED unset When present with any value, inbound callbacks, feedback, and slash commands still work, but plain text/photo/image-document messages do not launch agents.

How It Works

Outbound

The outbound script acquires an exclusive file lock (to prevent concurrent runs from duplicating sends), loads unsent notifications using a high-water mark timestamp, and formats them as Telegram MarkdownV2 messages with inline keyboards. Long plans are wrapped in expandable blockquotes or truncated and paired with a document attachment. Chat file attachments are trimmed to just the response portion, with commit messages and diffs embedded into the response PDF when possible. Actionable notifications (plan approvals, HITL requests, user questions) are saved as pending actions for the inbound script to match against.

Inbound

The inbound script fetches Telegram button presses, text messages, and photo/document uploads. It processes inline keyboard callbacks (approve/run/reject/select/epic/legend, agent controls, and bead pickers), handles two-step feedback flows (Feedback/Custom button followed by a reply or single active text response), and writes response files for sase to pick up. Text messages that don't complete a feedback flow are dispatched as follows:

  • Slash commands (/list, /kill [<name>], /fork, /changes [project], /xprompts, /bead [<id>], /update) — agent management, ChangeSpec workflow tag lookup, xprompt catalog export, bead inspection, and SASE updates
  • Other slash commands (/start, unknown commands, etc.) — silently ignored
  • Everything else — launches a new sase agent with the message as the prompt

Agent launches expand xprompt references, support multi-model directives, and auto-assign names. Launch confirmation messages include Fork and Wait copy-text buttons plus Kill and Retry controls for quick follow-up actions.

Photos and image documents launch agents with prompts that reference the downloaded local image path. Telegram albums are staged briefly and then launched as one prompt containing a numbered list of all downloaded image paths, so prompt image discovery can surface every file later.

Set SASE_TELEGRAM_LAUNCH_AGENTS_DISABLED on hosts that should process Telegram callbacks, feedback, and slash commands without launching new agents from free-form text, photos, image documents, or albums. The check is presence-based, so an empty value still disables launches; ignored launch messages are logged without a Telegram acknowledgement.

/changes lists active ChangeSpecs, excluding Submitted, Archived, and Reverted entries. Use /changes <project> to filter by exact project name. Each result has a copy-text button for the bare workflow tag, such as #hg:foobar.

/bead lists active beads across all known SASE projects as picker buttons. /bead <id> runs sase bead show <id>, converts the output to Telegram MarkdownV2, and sends the bead details in chat. If SASE_TELEGRAM_BEAD_PROJECT is set, bead commands are narrowed to that project workspace. Without the override, detail lookup searches known projects and prefers the chat-scoped project remembered from recent Telegram launch context.

/update starts the shared SASE chat update worker in a detached process and immediately replies with the worker log path. The worker stops axe, syncs the primary SASE workspace, runs chat_install.command from that workspace, and attempts to start axe again even when sync or install fails. After the worker exits, the next inbound run sends a completion message that reports success or the failure exit code and includes the worker log path.

Slash command registration is cached in ~/.sase/telegram/commands_registered_ts, but the cache includes a fingerprint of the command list so renamed commands are registered immediately after deployment.

State Files

State files are stored under ~/.sase/telegram/:

File Purpose
pending_actions.json Pending notification, kill, retry, and bead callback context
rate_limit.json Sliding-window send timestamps
update_offset.txt Last processed Telegram update ID
awaiting_feedback.json Active two-step feedback flow state, keyed by Telegram message
media_groups.json Staged Telegram photo/image-document albums waiting for the quiet window
last_sent_ts High-water mark for outbound notifications
outbound.lock Exclusive lock for outbound process
outbound_debug.log Diagnostic log for outbound sends
commands_registered_ts Cached timestamp and fingerprint for Telegram slash command registration
images/ Downloaded photos and image documents from Telegram messages

Requirements

  • Python 3.12+
  • sase >= 0.1.0
  • python-telegram-bot >= 21.0
  • pass (for bot token retrieval)
  • PDF tooling supported by SASE's shared Markdown renderer (optional, for PDF generation)

Development

just install    # Install in editable mode with dev deps
just fmt        # Auto-format code
just lint       # Run ruff + mypy
just test       # Run tests
just check      # All checks (lint + test)
just build      # Build distribution packages
just clean      # Remove build artifacts

Project Structure

src/sase_telegram/
├── __init__.py              # Package init
├── callback_data.py         # Encode/decode inline keyboard callback data (64-byte limit)
├── credentials.py           # Bot token sources, chat ID, and username
├── formatting.py            # Notification → Telegram MarkdownV2 formatting + inline keyboards
├── inbound.py               # Pure logic: callback decoding, two-step feedback, photo handling
├── bead_format.py           # Convert `sase bead` output to Markdown for Telegram rendering
├── outbound.py              # High-water mark tracking, exclusive lock, unsent detection
├── pending_actions.py       # Persist pending actions to JSON (24h stale cleanup)
├── rate_limit.py            # Sliding-window rate limiter (configurable via env var)
├── telegram_client.py       # Sync wrapper with retry/backoff and message splitting
├── pdf_convert.py           # Markdown to PDF via SASE's shared renderer
├── pdf_style.css            # CSS styling for rendered PDF output
└── scripts/
    ├── __init__.py           # Re-exports inbound_main and outbound_main
    ├── sase_tg_outbound.py   # Outbound entry point (--dry-run, --context)
    └── sase_tg_inbound.py    # Inbound entry point (--once, --context)

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sase_telegram-0.2.3.tar.gz (207.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sase_telegram-0.2.3-py3-none-any.whl (67.2 kB view details)

Uploaded Python 3

File details

Details for the file sase_telegram-0.2.3.tar.gz.

File metadata

  • Download URL: sase_telegram-0.2.3.tar.gz
  • Upload date:
  • Size: 207.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sase_telegram-0.2.3.tar.gz
Algorithm Hash digest
SHA256 3e5bf38cba097ca01c67ca555f414be640bf7a968926ff8489e81c183cc25063
MD5 32ac332d3b878d2ed649f44181d6888d
BLAKE2b-256 948d5f1e96e2d44f2fd53115bd0f6413ae80a882edb4fc0b677a5ce0288f1ca3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sase_telegram-0.2.3.tar.gz:

Publisher: publish.yml on sase-org/sase-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sase_telegram-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: sase_telegram-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 67.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sase_telegram-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a2ec698db532c5365c131bccc31d3d5887f246cca16c1dcfbc1423cb2953dc9f
MD5 a82504b45b2f31b63a06ee9c83e5249d
BLAKE2b-256 3d6cad0c4e8779a64d2ad492699cc8fb599e1c76423053c736067ed395a24594

See more details on using hashes here.

Provenance

The following attestation bundles were made for sase_telegram-0.2.3-py3-none-any.whl:

Publisher: publish.yml on sase-org/sase-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page