forked from trpc-group/trpc-agent-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_telegram.py
More file actions
67 lines (55 loc) · 2.52 KB
/
Copy path_telegram.py
File metadata and controls
67 lines (55 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# This file is part of tRPC-Agent-Python and is licensed under Apache-2.0.
#
# Portions of this file are derived from HKUDS/nanobot (MIT License):
# https://github.com/HKUDS/nanobot.git
#
# Copyright (c) 2025 nanobot contributors
#
# See the project LICENSE / third-party attribution notices for details.
#
"""Telegram channel for trpc_claw."""
from nanobot.channels.manager import ChannelManager
from nanobot.channels.telegram import TelegramChannel as NanobotTelegramChannel
from telegram import Update
from telegram.ext import ContextTypes
from ..config import BOT_NAME
from ._repair import register_channel_repair
class TelegramChannel(NanobotTelegramChannel):
"""Telegram channel for trpc_claw."""
async def _on_start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle /start command."""
if not update.message or not update.effective_user:
return
user = update.effective_user
await update.message.reply_text(f"👋 Hi {user.first_name}! I'm {BOT_NAME}.\n\n"
"Send me a message and I'll respond!\n"
"Type /help to see available commands.")
async def _on_help(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle /help command, bypassing ACL so all users can access it."""
if not update.message:
return
await update.message.reply_text(f"{BOT_NAME} commands:\n"
"/new — Start a new conversation\n"
"/stop — Stop the current task\n"
"/help — Show available commands")
def repair_telegram_channel(name: str, channel_manager: ChannelManager) -> None:
"""Repair the telegram channel.
Args:
channel_manager: ChannelManager instance.
"""
section = getattr(channel_manager.config.channels, name, None)
if not section:
return
enabled = (section.get("enabled", False) if isinstance(section, dict) else getattr(section, "enabled", False))
if not enabled:
return
channel_manager.channels[name] = TelegramChannel(
channel_manager.config.channels,
channel_manager.bus,
groq_api_key=channel_manager.config.providers.groq.api_key,
)
register_channel_repair("telegram", repair_telegram_channel)