openclaw - 💡(How to fix) Fix [Feature request] Message egress redactor hook for Telegram / other channels [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#69610Fetched 2026-04-22 07:50:15
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

There's no beforeSend (or equivalent) hook for outbound message text across chat channels, so operators can't apply secret/PII redaction to outbound text before bot.api.sendMessage fires. v2026.4.15 already ships redactExecApprovals for exec-approval prompt text (CHANGELOG #88, #61077, #333); this is a request to extend the same philosophy to the general message egress path.

Error Message

In a cron-heavy agent setup (weekly reports, error summaries, audit pings), agent output is pushed to Telegram via delivery.channel: telegram. Failure modes where secrets can slip through:

  • A subprocess error the agent relays verbatim containing a Bearer token or DB URI
  • An error trace with a PGPASSWORD env var that made it into stderr

Root Cause

There's no beforeSend (or equivalent) hook for outbound message text across chat channels, so operators can't apply secret/PII redaction to outbound text before bot.api.sendMessage fires. v2026.4.15 already ships redactExecApprovals for exec-approval prompt text (CHANGELOG #88, #61077, #333); this is a request to extend the same philosophy to the general message egress path.

Fix Action

Fix / Workaround

Why not just patch dist/ locally

  • OpenClaw releases are frequent (CHANGELOG shows several 2026.4.x releases already); each vendor patch gets wiped on upgrade
  • Plugin-SDK extension point keeps the security contract inside the vendor surface and survives upgrades

Code Example

// e.g. ~/.openclaw/config.json
{
  "security": {
    "messageEgressRedactor": {
      // Option A: spawn a subprocess that reads text on stdin, writes redacted text on stdout
      "command": ["python3", "/home/user/.openclaw/workspace/scripts/redact.py"],
      // Option B: path to a JS module exporting `redact(text: string) => string | Promise<string>`
      "modulePath": "/path/to/egress-redactor.js",
      // Fail-closed: if redactor crashes or times out, DO NOT send raw text
      "failClosed": true,
      "timeoutMs": 5000
    }
  }
}

---

// plugin-sdk/hook-runtime
export type BeforeMessageSendHook = (ctx: {
  channel: "telegram" | "discord" | ...;
  chatId: string;
  text: string;
  // immutable metadata
  agentId?: string;
  jobId?: string;
}) => string | Promise<string>;

registerBeforeMessageSendHook(fn);
RAW_BUFFERClick to expand / collapse

[Feature request] Message egress redactor hook for Telegram / other channels

Summary

There's no beforeSend (or equivalent) hook for outbound message text across chat channels, so operators can't apply secret/PII redaction to outbound text before bot.api.sendMessage fires. v2026.4.15 already ships redactExecApprovals for exec-approval prompt text (CHANGELOG #88, #61077, #333); this is a request to extend the same philosophy to the general message egress path.

Motivation

In a cron-heavy agent setup (weekly reports, error summaries, audit pings), agent output is pushed to Telegram via delivery.channel: telegram. Failure modes where secrets can slip through:

  • A subprocess error the agent relays verbatim containing a Bearer token or DB URI
  • An error trace with a PGPASSWORD env var that made it into stderr
  • A tool output containing an internal hostname or private IP that would leak infra topology

Operators can redact from their own scripts (e.g. by piping through a local redact.py), but any job whose output path is agent-turn → channel delivery skips the operator's redactor entirely.

Current state (what I found reading dist/)

  • dist/extensions/telegram/delivery-AYrG1NE_.js:69 sendTelegramText(bot, chatId, text, runtime, opts)bot.api.sendMessage(chatId, formattedText, ...)
  • plugin-sdk/hook-runtime has fireAndForgetHook / triggerInternalHook but these fire the SentMessage context after the call; they don't allow mutating text
  • redactWebhookUrl, redactConfigSnapshot, redactExecApprovals exist for other egress points but not for general message text

Proposal

Add a messageEgressRedactor operator config option and/or a plugin-SDK beforeMessageSend hook:

// e.g. ~/.openclaw/config.json
{
  "security": {
    "messageEgressRedactor": {
      // Option A: spawn a subprocess that reads text on stdin, writes redacted text on stdout
      "command": ["python3", "/home/user/.openclaw/workspace/scripts/redact.py"],
      // Option B: path to a JS module exporting `redact(text: string) => string | Promise<string>`
      "modulePath": "/path/to/egress-redactor.js",
      // Fail-closed: if redactor crashes or times out, DO NOT send raw text
      "failClosed": true,
      "timeoutMs": 5000
    }
  }
}

Or plugin SDK:

// plugin-sdk/hook-runtime
export type BeforeMessageSendHook = (ctx: {
  channel: "telegram" | "discord" | ...;
  chatId: string;
  text: string;
  // immutable metadata
  agentId?: string;
  jobId?: string;
}) => string | Promise<string>;

registerBeforeMessageSendHook(fn);

Cross-channel uniformity: whatever mechanism is chosen, it should apply to Telegram, Discord, Slack, IRC, Matrix, Feishu, WhatsApp — anywhere bot.api.sendMessage-like text egress happens. Media captions (e.g. deliverMediaReply) should run through the same redactor.

Why not just patch dist/ locally

  • OpenClaw releases are frequent (CHANGELOG shows several 2026.4.x releases already); each vendor patch gets wiped on upgrade
  • Plugin-SDK extension point keeps the security contract inside the vendor surface and survives upgrades

Related existing code to reuse

  • Pattern from redactExecApprovals (around dist/server.impl-*.js:9791) is already similar — centralized text redaction applied before posting back to chat
  • The runtimeConfig schema already has security-relevant sections (SSRF, webhook signing); messageEgressRedactor would slot naturally there

Ack

Happy to contribute a PR if the API shape is agreed on. Would prefer:

  • Config option + subprocess support (language-agnostic, operators likely already have redactors in Python/Go/etc.)
  • Plus the hook API for plugin authors

Originally reported by an operator using a local Python redactor (~/workspace/scripts/redact.py, fail-closed default + 7-family token coverage). Reproducer environment: v2026.4.15 on Linux (WSL2), Node 22.22.0.

extent analysis

TL;DR

Implement a messageEgressRedactor operator config option and/or a plugin-SDK beforeMessageSend hook to enable secret/PII redaction for outbound message text across chat channels.

Guidance

  • Review the proposed messageEgressRedactor config option and beforeMessageSend hook API to ensure they meet the requirements for cross-channel uniformity and security.
  • Consider reusing the pattern from redactExecApprovals and integrating the messageEgressRedactor config into the existing runtimeConfig schema.
  • Evaluate the trade-offs between using a subprocess-based approach (e.g., with a Python redactor) versus a JavaScript module-based approach for the redactor implementation.
  • Test the proposed solution with various chat channels (e.g., Telegram, Discord, Slack) to ensure compatibility and effectiveness.

Example

// Example messageEgressRedactor config
{
  "security": {
    "messageEgressRedactor": {
      "command": ["python3", "/home/user/.openclaw/workspace/scripts/redact.py"],
      "failClosed": true,
      "timeoutMs": 5000
    }
  }
}

Notes

The proposed solution aims to provide a flexible and secure way to redact sensitive information from outbound message text. However, the implementation details and potential edge cases will require careful consideration to ensure the solution is effective and reliable.

Recommendation

Apply the proposed messageEgressRedactor config option and/or beforeMessageSend hook API as a workaround to enable secret/PII redaction for outbound message text. This approach allows for a flexible and secure solution that can be tailored to specific use cases and chat channels.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature request] Message egress redactor hook for Telegram / other channels [1 participants]