feat(agent-office): /watch /unwatch /watchlist 봇 명령
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""텔레그램 Webhook 이벤트 처리."""
|
||||
from typing import Optional
|
||||
|
||||
from .. import service_proxy
|
||||
from ..db import get_telegram_callback, mark_telegram_responded
|
||||
from .client import _enabled, api_call
|
||||
|
||||
@@ -23,12 +24,43 @@ async def handle_webhook(data: dict, agent_dispatcher=None) -> Optional[dict]:
|
||||
if message:
|
||||
chat = message.get("chat", {})
|
||||
print(f"[TG-WEBHOOK] chat.id={chat.get('id')} type={chat.get('type')} text={message.get('text')!r}", flush=True)
|
||||
if message and message.get("text"):
|
||||
if await handle_watch_command(message):
|
||||
return None
|
||||
if message and message.get("text") and agent_dispatcher is not None:
|
||||
return await _handle_message(message, agent_dispatcher)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
async def handle_watch_command(message: dict) -> bool:
|
||||
"""/watch /unwatch /watchlist 명령을 처리해 stock watchlist API로 프록시.
|
||||
|
||||
처리했으면(응답 전송 포함) True, 매칭되지 않는 텍스트면 False."""
|
||||
text = (message.get("text") or "").strip()
|
||||
chat_id = message.get("chat", {}).get("id")
|
||||
parts = text.split()
|
||||
cmd = parts[0].lower() if parts else ""
|
||||
|
||||
if cmd == "/watch" and len(parts) >= 2:
|
||||
await service_proxy.watchlist_add(parts[1])
|
||||
reply = f"관심종목 추가: {parts[1]}"
|
||||
elif cmd == "/unwatch" and len(parts) >= 2:
|
||||
await service_proxy.watchlist_remove(parts[1])
|
||||
reply = f"관심종목 삭제: {parts[1]}"
|
||||
elif cmd == "/watchlist":
|
||||
res = await service_proxy.watchlist_list()
|
||||
items = res.get("watchlist", [])
|
||||
reply = "관심종목:\n" + (
|
||||
"\n".join(f"- {w.get('name') or ''} ({w['ticker']})" for w in items) or "(없음)"
|
||||
)
|
||||
else:
|
||||
return False
|
||||
|
||||
await api_call("sendMessage", {"chat_id": chat_id, "text": reply})
|
||||
return True
|
||||
|
||||
|
||||
async def _handle_callback(callback_query: dict) -> Optional[dict]:
|
||||
"""승인/거절 및 realestate 북마크 콜백 처리."""
|
||||
callback_id = callback_query.get("data", "")
|
||||
|
||||
Reference in New Issue
Block a user