Saves user message to the database and updates session title/time.
(self, content: str, display_content: str, file_name: str, is_onboarding_trigger: bool)
| 611 | return False |
| 612 | |
| 613 | async def _save_user_message(self, content: str, display_content: str, file_name: str, is_onboarding_trigger: bool): |
| 614 | """Saves user message to the database and updates session title/time.""" |
| 615 | has_image_marker = "[image_data:" in content |
| 616 | if has_image_marker: |
| 617 | saved_content = f"[file:{file_name}]\n{content}" if file_name else content |
| 618 | else: |
| 619 | saved_content = display_content if display_content else content |
| 620 | if file_name: |
| 621 | saved_content = f"[file:{file_name}]\n{saved_content}" |
| 622 | |
| 623 | if is_onboarding_trigger: |
| 624 | logger.info("[WS] Onboarding trigger — skipping user-message persistence") |
| 625 | async with async_session() as _sdb: |
| 626 | _sr = await _sdb.execute(select(ChatSession).where(ChatSession.id == uuid.UUID(self.conv_id))) |
| 627 | _s = _sr.scalar_one_or_none() |
| 628 | if _s and _s.title.startswith("Session "): |
| 629 | _s.title = "Onboarding" |
| 630 | await _sdb.commit() |
| 631 | else: |
| 632 | async with async_session() as db: |
| 633 | user_msg = ChatMessage( |
| 634 | agent_id=self.agent_id, |
| 635 | user_id=self.user.id, |
| 636 | role="user", |
| 637 | content=saved_content, |
| 638 | conversation_id=self.conv_id, |
| 639 | ) |
| 640 | db.add(user_msg) |
| 641 | # Update session |
| 642 | _now = datetime.now(tz.utc) |
| 643 | _sess_r = await db.execute(select(ChatSession).where(ChatSession.id == uuid.UUID(self.conv_id))) |
| 644 | _sess = _sess_r.scalar_one_or_none() |
| 645 | if _sess: |
| 646 | _sess.last_message_at = _now |
| 647 | if not self.history_messages and _sess.title.startswith("Session "): |
| 648 | title_src = display_content if display_content else content |
| 649 | clean_title = title_src.replace("[图片] ", "📷 ").replace("[image_data:", "").strip() |
| 650 | if file_name and not clean_title: |
| 651 | clean_title = f"📎 {file_name}" |
| 652 | _sess.title = clean_title[:40] if clean_title else content[:40] |
| 653 | await db.commit() |
| 654 | logger.info("[WS] User message saved") |
| 655 | |
| 656 | async def _route_openclaw(self, content: str): |
| 657 | """Enqueues message for OpenClaw edge node poll.""" |
no test coverage detected