gateway: add natural-language action mapping for reminders and mentor relay

This commit is contained in:
NODA1 System
2026-02-20 19:17:18 +01:00
parent c2f0b64604
commit ce6c9ec60a

View File

@@ -521,6 +521,57 @@ async def _handle_action_commands(
return None
def _extract_nl_action_command(text: str) -> Optional[str]:
t = (text or "").strip()
if not t or t.startswith("/"):
return None
low = t.lower()
# Reminder by relative duration (UA/RU/EN)
m = re.match(
r"^(?:нагадай(?:\s+мені)?|напомни(?:\s+мне)?|remind me)\s+(?:через|in)\s+(\d+)\s*(хв|мин|m|год|hour|h|дн|день|day|d)\s+(.+)$",
low,
)
if m:
value = m.group(1)
unit = m.group(2)
payload = t[m.end(2):].strip()
if payload:
norm = "m"
if unit in {"год", "hour", "h"}:
norm = "h"
elif unit in {"дн", "день", "day", "d"}:
norm = "d"
return f"/remind_in {value}{norm} {payload}"
# Reminder by absolute datetime (UA/RU/EN)
m2 = re.match(
r"^(?:нагадай(?:\s+мені)?|напомни(?:\s+мне)?|remind me)\s+(?:на|at)\s+(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2})\s+(.+)$",
low,
)
if m2:
dt = m2.group(1)
payload = t[m2.end(1):].strip()
if payload:
return f"/remind {dt} {payload}"
# Mentor relay intent
for prefix in (
"передай менторам ",
"надішли менторам ",
"напиши менторам ",
"send to mentors ",
"relay to mentors ",
):
if low.startswith(prefix):
payload = t[len(prefix):].strip()
if payload:
return f"/relay_mentors {payload}"
return None
def _extract_preferred_language_from_profile_fact(fact: Optional[Dict[str, Any]]) -> Optional[str]:
if not isinstance(fact, dict):
return None
@@ -2696,6 +2747,21 @@ async def handle_telegram_webhook(
)
if command_result is not None:
return command_result
nl_command = _extract_nl_action_command(text)
if nl_command:
logger.info(f"{agent_config.name}: NL action mapped to command: {nl_command}")
nl_result = await _handle_action_commands(
agent_config=agent_config,
text=nl_command,
chat_id=chat_id,
user_id=user_id,
username=username,
dao_id=dao_id,
telegram_token=telegram_token,
)
if nl_result is not None:
return nl_result
mentioned_bots = extract_bot_mentions(text)
needs_complex_reasoning = requires_complex_reasoning(text)