Compare commits
2 Commits
83a5d262c7
...
f47ffc93f4
| Author | SHA1 | Date | |
|---|---|---|---|
| f47ffc93f4 | |||
| e7ed81c189 |
+59
-45
@@ -675,13 +675,27 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
and decision.target_room != room_id
|
||||
and not getattr(decision, 'is_unrouteable', False)):
|
||||
|
||||
target_name = getattr(decision, 'matched_room_name', None) or 'Zielraum'
|
||||
target_name = getattr(decision, 'matched_room_name', None)
|
||||
if not target_name:
|
||||
# Fallback: Raum-Name aus room_info oder room_map
|
||||
target_name = self._room_info.get(decision.target_room, {}).get("name", "")
|
||||
if not target_name:
|
||||
# Letzter Fallback: room_map (wenn bekannt)
|
||||
for rid, entry in self.archivar._room_map.rooms.items():
|
||||
if rid == decision.target_room:
|
||||
target_name = entry.name
|
||||
break
|
||||
if not target_name:
|
||||
target_name = decision.target_room[:12] + "…" # ID-Fragment als Notlösung
|
||||
|
||||
if is_auftrag:
|
||||
# Typ 2: Buttons — User entscheidet
|
||||
# Typ 2: Nummerierte Optionen (keine nativen Buttons im Adapter)
|
||||
note = (
|
||||
f"Dein Auftrag passt thematisch besser in **{target_name}**.\n"
|
||||
f"Soll ich den Auftrag dorthin kopieren und dort abarbeiten?"
|
||||
f"Antworte mit einer Zahl:\n"
|
||||
f"1 = Ja, rüberkopieren und dort abarbeiten\n"
|
||||
f"2 = Hier bleiben\n"
|
||||
f"3 = Generell hier bleiben"
|
||||
)
|
||||
self._pending_move_requests[msg_id] = {
|
||||
"text": text,
|
||||
@@ -691,7 +705,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
"username": username,
|
||||
}
|
||||
self.rest.post_message(room_id, note)
|
||||
# Kein Forwarding — auf Button-Antwort warten
|
||||
# Kein Forwarding — auf numerische Antwort warten
|
||||
forwarded = True
|
||||
else:
|
||||
# Typ 1: Silent Copy — Nachricht in Zielraum kopieren
|
||||
@@ -1070,47 +1084,6 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
||||
|
||||
def _find_fallback_room_for_user(self, chat_id: str) -> Optional[str]:
|
||||
"""Fallback method to find a room for a user when direct mapping fails.
|
||||
|
||||
Args:
|
||||
chat_id: Virtual chat_id like "user:username"
|
||||
|
||||
Returns:
|
||||
Room ID if found, None otherwise
|
||||
"""
|
||||
if not chat_id.startswith("user:"):
|
||||
return None
|
||||
|
||||
target_username = chat_id.split(":", 1)[1].lower()
|
||||
|
||||
# Try to find any DM room involving this user
|
||||
for room_id, room_info in self._room_info.items():
|
||||
if room_info.get("type") == "d":
|
||||
# Try to get room details with members
|
||||
try:
|
||||
room_detail = self.rest._request("GET", f"/api/v1/rooms.info?roomId={room_id}", headers={
|
||||
"X-Auth-Token": self.rest.auth_token,
|
||||
"X-User-Id": self.rest.user_id,
|
||||
})
|
||||
if room_detail and room_detail.get("success"):
|
||||
room_data = room_detail.get("room", {})
|
||||
usernames = room_data.get("usernames", [])
|
||||
if target_username in [u.lower() for u in usernames]:
|
||||
return room_id
|
||||
except Exception as e:
|
||||
logger.debug("[rocketchat] Could not get room info for %s: %s", room_id, e)
|
||||
|
||||
# Last resort: return first available room (better than nothing)
|
||||
if self._subscribed_rooms:
|
||||
first_room = next(iter(self._subscribed_rooms))
|
||||
logger.warning("[rocketchat] Using first available room %s as ultimate fallback for %s",
|
||||
first_room, chat_id)
|
||||
return first_room
|
||||
|
||||
return None
|
||||
|
||||
|
||||
# ── Minimal-Fix: Parse [[BUTTONS:...]] markup from agent response text ──
|
||||
# This allows the agent to request buttons by embedding markup in its
|
||||
# response text, without requiring the gateway to pass metadata.
|
||||
@@ -1209,6 +1182,47 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
return SendResult(success=True, message_id=str(int(time.time() * 1000)))
|
||||
return SendResult(success=False, error="chat.postMessage failed")
|
||||
|
||||
def _find_fallback_room_for_user(self, chat_id: str) -> Optional[str]:
|
||||
"""Fallback method to find a room for a user when direct mapping fails.
|
||||
|
||||
Args:
|
||||
chat_id: Virtual chat_id like "user:username"
|
||||
|
||||
Returns:
|
||||
Room ID if found, None otherwise
|
||||
"""
|
||||
if not chat_id.startswith("user:"):
|
||||
return None
|
||||
|
||||
target_username = chat_id.split(":", 1)[1].lower()
|
||||
|
||||
# Try to find any DM room involving this user
|
||||
for room_id, room_info in self._room_info.items():
|
||||
if room_info.get("type") == "d":
|
||||
# Try to get room details with members
|
||||
try:
|
||||
room_detail = self.rest._request("GET", f"/api/v1/rooms.info?roomId={room_id}", headers={
|
||||
"X-Auth-Token": self.rest.auth_token,
|
||||
"X-User-Id": self.rest.user_id,
|
||||
})
|
||||
if room_detail and room_detail.get("success"):
|
||||
room_data = room_detail.get("room", {})
|
||||
usernames = room_data.get("usernames", [])
|
||||
if target_username in [u.lower() for u in usernames]:
|
||||
return room_id
|
||||
except Exception as e:
|
||||
logger.debug("[rocketchat] Could not get room info for %s: %s", room_id, e)
|
||||
|
||||
# Last resort: return first available room (better than nothing)
|
||||
if self._subscribed_rooms:
|
||||
first_room = next(iter(self._subscribed_rooms))
|
||||
logger.warning("[rocketchat] Using first available room %s as ultimate fallback for %s",
|
||||
first_room, chat_id)
|
||||
return first_room
|
||||
|
||||
return None
|
||||
|
||||
|
||||
async def send_typing(self, chat_id: str, metadata=None) -> None:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user