hermes - 💡(How to fix) Fix Feature request: pre_gateway_text_send hook for outbound message interception [1 pull requests]

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…

Fix Action

Fixed

Code Example

{
    "text": str,        # The outbound message text
    "platform": str,    # Platform name (e.g. "telegram", "discord")
    "chat_id": str,     # Target chat/channel ID
}

---

# fact-guard hook handler
def handle(event_type, context):
    text = context.get("text", "")
    if "misinformation_pattern" in text:
        return None  # block
    return text.replace("bad", "good")  # rewrite
RAW_BUFFERClick to expand / collapse

Use case

Plugins (e.g. fact-guard) need the ability to intercept and potentially rewrite or block outbound text messages before they are sent to messaging platforms (Telegram, Discord, WhatsApp, etc.).

Currently, the gateway hook system (gateway/hooks.py) supports lifecycle events like agent:start, agent:end, command:*, and session:*, but there is no hook that fires when a text response is about to be sent to a platform adapter.

Proposed solution

Add a new hook event pre_gateway_text_send that fires with emit_collect before a text response is delivered to the platform adapter. The hook receives context:

{
    "text": str,        # The outbound message text
    "platform": str,    # Platform name (e.g. "telegram", "discord")
    "chat_id": str,     # Target chat/channel ID
}

Handlers can return:

  • A str → use this as the rewritten message text
  • None → block delivery entirely
  • Any other value → pass the original text through unchanged

Example plugin use

# fact-guard hook handler
def handle(event_type, context):
    text = context.get("text", "")
    if "misinformation_pattern" in text:
        return None  # block
    return text.replace("bad", "good")  # rewrite

Implementation

See PR for the implementation, which:

  1. Documents the new event in gateway/hooks.py
  2. Emits the hook in _handle_message_with_agent() before the response is returned to the adapter
  3. Uses emit_collect so multiple handlers can chain (last non-None rewrite wins, first None blocks)

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

hermes - 💡(How to fix) Fix Feature request: pre_gateway_text_send hook for outbound message interception [1 pull requests]