feat: Ollama qwen3:14b 기반 AI 뉴스 요약 + 텔레그램 통합 허브
- stock-lab: POST /api/stock/news/summarize 추가 (Ollama /api/generate 호출, 토큰/duration 추적)
- agent-office: telegram 패키지 분해 (client/formatter/messaging/webhook/router/agent_registry)
- send_agent_message 통합 API로 에이전트 중립 메시지 포맷 표준화
- 텔레그램 → 에이전트 명령 라우터 (/status, /stock news, /music credits 등)
- 토큰 사용량 집계 API 및 GET /agents/{id}/token-usage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
68
agent-office/app/telegram/messaging.py
Normal file
68
agent-office/app/telegram/messaging.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""고수준 메시지 전송 API."""
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from ..config import TELEGRAM_CHAT_ID
|
||||
from ..db import save_telegram_callback
|
||||
from .client import _enabled, api_call
|
||||
from .formatter import MessageKind, format_agent_message
|
||||
|
||||
|
||||
async def send_raw(text: str, reply_markup: Optional[dict] = None) -> dict:
|
||||
"""가장 저수준. 원문 텍스트 그대로 전송."""
|
||||
if not _enabled():
|
||||
return {"ok": False, "message_id": None}
|
||||
payload = {
|
||||
"chat_id": TELEGRAM_CHAT_ID,
|
||||
"text": text,
|
||||
"parse_mode": "HTML",
|
||||
}
|
||||
if reply_markup:
|
||||
payload["reply_markup"] = reply_markup
|
||||
result = await api_call("sendMessage", payload)
|
||||
return {
|
||||
"ok": result.get("ok", False),
|
||||
"message_id": result.get("result", {}).get("message_id") if result.get("ok") else None,
|
||||
}
|
||||
|
||||
|
||||
async def send_agent_message(
|
||||
agent_id: str,
|
||||
kind: MessageKind,
|
||||
title: str,
|
||||
body: str,
|
||||
task_id: Optional[str] = None,
|
||||
actions: Optional[list] = None,
|
||||
metadata: Optional[dict] = None,
|
||||
) -> dict:
|
||||
"""통합 에이전트 메시지 API. 모든 에이전트가 이걸 씀."""
|
||||
text = format_agent_message(agent_id, kind, title, body, metadata)
|
||||
reply_markup = None
|
||||
if actions:
|
||||
buttons = []
|
||||
for action in actions:
|
||||
cb_id = f"{action['action']}_{uuid.uuid4().hex[:8]}"
|
||||
save_telegram_callback(cb_id, task_id or "", agent_id)
|
||||
buttons.append({"text": action["label"], "callback_data": cb_id})
|
||||
reply_markup = {"inline_keyboard": [buttons]}
|
||||
return await send_raw(text, reply_markup)
|
||||
|
||||
|
||||
async def send_approval_request(
|
||||
agent_id: str,
|
||||
task_id: str,
|
||||
title: str,
|
||||
detail: str,
|
||||
) -> dict:
|
||||
"""승인/거절 단축 헬퍼."""
|
||||
return await send_agent_message(
|
||||
agent_id=agent_id,
|
||||
kind="approval",
|
||||
title=title,
|
||||
body=detail,
|
||||
task_id=task_id,
|
||||
actions=[
|
||||
{"label": "✅ 승인", "action": "approve"},
|
||||
{"label": "❌ 거절", "action": "reject"},
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user