diff --git a/xmpp_agent_core.py b/xmpp_agent_core.py
index 3ffe3e4..578c328 100644
--- a/xmpp_agent_core.py
+++ b/xmpp_agent_core.py
@@ -343,7 +343,6 @@ def _schedule_delayed(delay_sec: int, room: str):
"""Schedule ##delay:N## re-invocation."""
global _xmpp_ref
import subprocess as _sp
- from xml.sax.saxutils import escape
def _fire():
bot = _xmpp_ref
@@ -354,10 +353,9 @@ def _schedule_delayed(delay_sec: int, room: str):
raw = _call_llm(prompt, room, is_group=True)
reply = _extract_response(raw)
if reply:
- safe = escape(reply.strip())
- stanza = f"{safe}"
- bot.send_raw(stanza)
- log(f"-> [Delay][{room}]: {reply.strip()[:80]}")
+ text = reply.strip()
+ bot.send_message(mto=room, mbody=text, mtype='groupchat')
+ log(f"-> [Delay][{room}]: {text[:80]}")
except Exception as e:
log(f"!! delay err: {e}")
@@ -580,8 +578,7 @@ class _BridgeHandler(http.server.BaseHTTPRequestHandler):
safe = _escape(msg.strip())
bot = _xmpp_ref
if bot:
- stanza = f'{safe}'
- bot.send_raw(stanza)
+ bot.send_message(mto=to, mbody=msg.strip(), mtype='groupchat')
_record_group_msg(cfg["nick"], msg)
log(f"[http] → [{to.split('@')[0]}]: {msg[:80]}")
self._reply(200, {"ok": True})
@@ -634,12 +631,11 @@ def _process_llm_reply(raw_reply: str, room: str):
# Extract actual response
reply_text = _extract_response(raw_reply)
if reply_text:
- safe = _escape(reply_text.strip())
+ text = reply_text.strip()
bot = _xmpp_ref
if bot:
- stanza = f"{safe}"
- bot.send_raw(stanza)
- log(f"-> [{room.split('@')[0]}]: {reply_text.strip()[:80]}")
+ bot.send_message(mto=room, mbody=text, mtype='groupchat')
+ log(f"-> [{room.split('@')[0]}]: {text[:80]}")
else:
log(f"-> [{room.split('@')[0]}]: (silent)")
_batch_done(room)
@@ -716,21 +712,11 @@ def _handle_private_message(msg):
if raw:
reply = _extract_response(raw)
if reply:
- from xml.sax.saxutils import escape
- safe = escape(reply.strip())
- if _IS_CHAT_BRIDGE:
- bot = _xmpp_ref
- if bot:
- stanza = f"{safe}"
- bot.send_raw(stanza)
- log(f"-> {sender}: {reply.strip()[:80]}")
- else:
- import subprocess as sp
- sp.run(["docker", "exec", "ejabberd", "ejabberdctl", "send_stanza",
- cfg["jid"], sender,
- f"{safe}"
- ], capture_output=True, timeout=10)
- log(f"-> {sender}: {reply.strip()[:80]}")
+ text = reply.strip()
+ bot = _xmpp_ref
+ if bot:
+ bot.send_message(mto=sender, mbody=text, mtype='chat')
+ log(f"-> {sender}: {text[:80]}")
# ═══════════════════════════════════════════════════════════════