Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,23 @@ def get_sender_name(message) -> str:
return "Unknown"


def get_engagement_info(message) -> str:
"""Helper function to get engagement metrics (views, forwards, reactions) from a message."""
engagement_parts = []
views = getattr(message, "views", None)
if views is not None:
engagement_parts.append(f"views:{views}")
forwards = getattr(message, "forwards", None)
if forwards is not None:
engagement_parts.append(f"forwards:{forwards}")
reactions = getattr(message, "reactions", None)
if reactions is not None:
results = getattr(reactions, "results", None)
total_reactions = sum(getattr(r, "count", 0) or 0 for r in results) if results else 0
engagement_parts.append(f"reactions:{total_reactions}")
return f" | {', '.join(engagement_parts)}" if engagement_parts else ""


@mcp.tool(annotations=ToolAnnotations(title="Get Chats", openWorldHint=True, readOnlyHint=True))
async def get_chats(page: int = 1, page_size: int = 20) -> str:
"""
Expand Down Expand Up @@ -365,8 +382,11 @@ async def get_messages(chat_id: Union[int, str], page: int = 1, page_size: int =
reply_info = ""
if msg.reply_to and msg.reply_to.reply_to_msg_id:
reply_info = f" | reply to {msg.reply_to.reply_to_msg_id}"

engagement_info = get_engagement_info(msg)

lines.append(
f"ID: {msg.id} | {sender_name} | Date: {msg.date}{reply_info} | Message: {msg.message}"
f"ID: {msg.id} | {sender_name} | Date: {msg.date}{reply_info}{engagement_info} | Message: {msg.message}"
)
return "\n".join(lines)
except Exception as e:
Expand Down Expand Up @@ -796,8 +816,10 @@ async def list_messages(
if msg.reply_to and msg.reply_to.reply_to_msg_id:
reply_info = f" | reply to {msg.reply_to.reply_to_msg_id}"

engagement_info = get_engagement_info(msg)

lines.append(
f"ID: {msg.id} | {sender_name} | Date: {msg.date}{reply_info} | Message: {message_text}"
f"ID: {msg.id} | {sender_name} | Date: {msg.date}{reply_info}{engagement_info} | Message: {message_text}"
)

return "\n".join(lines)
Expand Down