Skip to content

Agent Zero AI framework

feat(telegram): add welcome message for new group members

keyboardstaff4a06e0c05ea7
diff --git a/plugins/_telegram_integration/default_config.yaml b/plugins/_telegram_integration/default_config.yaml
index 5e06e6e3f..34c488346 100644
--- a/plugins/_telegram_integration/default_config.yaml
+++ b/plugins/_telegram_integration/default_config.yaml
@@ -9,6 +9,8 @@ bots: []
# webhook_secret: "" # optional shared secret for webhook verification
# allowed_users: [] # Telegram user IDs or @usernames. Empty = allow all.
# group_mode: mention # mention (respond when @mentioned or replied to) | all (respond to every message) | off (ignore groups)
+# welcome_enabled: false # Send a greeting when someone joins the group
+# welcome_message: "" # Welcome template. Use {name} for the new member's name. Default: "Welcome, {name}!"
# user_projects: {} # Map Telegram user_id to project name, e.g. { "123456": "my_project" }
# default_project: "" # Fallback project if user not in user_projects
# attachment_max_age_hours: 0 # Hours to keep downloaded attachments. 0 = keep forever.
diff --git a/plugins/_telegram_integration/extensions/python/job_loop/_10_telegram_bot.py b/plugins/_telegram_integration/extensions/python/job_loop/_10_telegram_bot.py
index 7a87ce8bb..00128e8b4 100644
--- a/plugins/_telegram_integration/extensions/python/job_loop/_10_telegram_bot.py
+++ b/plugins/_telegram_integration/extensions/python/job_loop/_10_telegram_bot.py
@@ -26,6 +26,7 @@ class TelegramBotManager(Extension):
handle_clear,
handle_message,
handle_callback_query,
+ handle_new_members,
cleanup_old_attachments,
)
@@ -67,6 +68,7 @@ class TelegramBotManager(Extension):
_on_clear = partial(_wrap_clear, bot_name=name, bot_cfg=bot_cfg)
_on_message = partial(_wrap_message, bot_name=name, bot_cfg=bot_cfg)
_on_callback = partial(_wrap_callback, bot_name=name, bot_cfg=bot_cfg)
+ _on_new_members = partial(_wrap_new_members, bot_name=name, bot_cfg=bot_cfg)
instance = create_bot(
name=name,
@@ -75,6 +77,7 @@ class TelegramBotManager(Extension):
on_command_start=_on_start,
on_command_clear=_on_clear,
on_callback_query=_on_callback,
+ on_new_members=_on_new_members,
group_mode=bot_cfg.get("group_mode", "mention"),
)
@@ -130,3 +133,8 @@ async def _wrap_message(message, bot_name: str, bot_cfg: dict):
async def _wrap_callback(query, bot_name: str, bot_cfg: dict):
from plugins._telegram_integration.helpers.handler import handle_callback_query
await handle_callback_query(query, bot_name, _get_current_bot_cfg(bot_name) or bot_cfg)
+
+
+async def _wrap_new_members(message, bot_name: str, bot_cfg: dict):
+ from plugins._telegram_integration.helpers.handler import handle_new_members
+ await handle_new_members(message, bot_name, _get_current_bot_cfg(bot_name) or bot_cfg)
diff --git a/plugins/_telegram_integration/helpers/bot_manager.py b/plugins/_telegram_integration/helpers/bot_manager.py
index ef2d138eb..14b057903 100644
--- a/plugins/_telegram_integration/helpers/bot_manager.py
+++ b/plugins/_telegram_integration/helpers/bot_manager.py
@@ -4,7 +4,7 @@ from typing import Callable, Awaitable
from aiogram import Bot, Dispatcher, Router, F
from aiogram.client.default import DefaultBotProperties
-from aiogram.enums import ParseMode, ChatType
+from aiogram.enums import ParseMode, ChatType, ContentType
from aiogram.filters import Command, CommandStart
from aiogram.types import Message
@@ -46,6 +46,7 @@ def create_bot(
on_command_start: Callable[..., Awaitable],
on_command_clear: Callable[..., Awaitable],
on_callback_query: Callable[..., Awaitable] | None = None,
+ on_new_members: Callable[..., Awaitable] | None = None,
group_mode: str = "mention",
) -> BotInstance:
bot = Bot(token=token, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
@@ -59,6 +60,9 @@ def create_bot(
if on_callback_query:
router.callback_query.register(on_callback_query)
+ if on_new_members:
+ router.message.register(on_new_members, F.content_type == ContentType.NEW_CHAT_MEMBERS)
+
# Register message handler with group filtering
if group_mode == "off":
# Private chats only
diff --git a/plugins/_telegram_integration/helpers/handler.py b/plugins/_telegram_integration/helpers/handler.py
index d4927212f..713dc5cbe 100644
--- a/plugins/_telegram_integration/helpers/handler.py
+++ b/plugins/_telegram_integration/helpers/handler.py
@@ -289,6 +289,31 @@ async def handle_callback_query(query: CallbackQuery, bot_name: str, bot_cfg: di
context.communicate(UserMessage(message=user_msg))
save_tmp_chat(context)
+
+async def handle_new_members(message: TgMessage, bot_name: str, bot_cfg: dict):
+ """Send welcome message when new members join a group."""
+ if not bot_cfg.get("welcome_enabled", False):
+ return
+
+ new_members = message.new_chat_members or []
+ if not new_members:
+ return
+
+ instance = get_bot(bot_name)
+ if not instance:
+ return
+
+ template = bot_cfg.get("welcome_message", "").strip()
+ if not template:
+ template = "Welcome, {name}!"
+
+ for member in new_members:
+ if member.is_bot:
+ continue
+ name = member.full_name or member.first_name or str(member.id)
+ text = template.replace("{name}", name)
+ await _send_with_temp_bot(instance.bot.token, message.chat.id, text, parse_mode=None)
+
# Context management
async def _get_or_create_context(
diff --git a/plugins/_telegram_integration/webui/config.html b/plugins/_telegram_integration/webui/config.html
index 696d95d3e..3277f0d5a 100644
--- a/plugins/_telegram_integration/webui/config.html
+++ b/plugins/_telegram_integration/webui/config.html
@@ -179,6 +179,29 @@
</div>
</div>
+ <div class="field" x-show="bot.group_mode !== 'off'">
+ <div class="field-label">
+ <div class="field-title">Welcome New Members</div>
+ <div class="field-description">Send a greeting when someone joins the group</div>
+ </div>
+ <div class="field-control">
+ <label class="toggle">
+ <input type="checkbox" x-model="bot.welcome_enabled" />
+ <span class="toggler"></span>
+ </label>
+ </div>
+ </div>
+
+ <div class="field" x-show="bot.group_mode !== 'off' && bot.welcome_enabled">
+ <div class="field-label">
+ <div class="field-title">Welcome Message</div>
+ <div class="field-description">Use {name} for the new member's name</div>
+ </div>
+ <div class="field-control">
+ <input type="text" x-model="bot.welcome_message" placeholder="Welcome, {name}!" />
+ </div>
+ </div>
+
<div class="field">
<div class="field-label">
<div class="field-title">User Project Mapping</div>
diff --git a/plugins/_telegram_integration/webui/telegram-config-store.js b/plugins/_telegram_integration/webui/telegram-config-store.js
index 5a5383ee1..ff958b0f6 100644
--- a/plugins/_telegram_integration/webui/telegram-config-store.js
+++ b/plugins/_telegram_integration/webui/telegram-config-store.js
@@ -32,6 +32,8 @@ export const store = createStore("telegramConfig", {
webhook_secret: "",
allowed_users: [],
group_mode: "mention",
+ welcome_enabled: false,
+ welcome_message: "",
user_projects: {},
default_project: "",
agent_instructions: "",