feat: route telegram eba events to plugins

This commit is contained in:
Junyan Qin
2026-05-07 17:02:49 +08:00
parent e4a471af18
commit 5c182c0f29
9 changed files with 573 additions and 14 deletions
@@ -154,6 +154,9 @@ class TelegramAdapter(TelegramAPIMixin, abstract_platform_adapter.AbstractPlatfo
'group.member_banned',
'bot.invited_to_group',
'bot.removed_from_group',
'bot.muted',
'bot.unmuted',
'platform.specific',
]
def get_supported_apis(self) -> list[str]:
@@ -221,27 +224,41 @@ class TelegramAdapter(TelegramAPIMixin, abstract_platform_adapter.AbstractPlatfo
components = await TelegramMessageConverter.yiri2target(message, self.bot)
for component in components:
if component['type'] == 'text':
component_type = component.get('type')
args = {
'chat_id': message_source.source_platform_object.effective_chat.id,
}
if message_source.source_platform_object.message.message_thread_id:
args['message_thread_id'] = message_source.source_platform_object.message.message_thread_id
if quote_origin:
args['reply_to_message_id'] = message_source.source_platform_object.message.id
if component_type == 'text':
if self.config['markdown_card'] is True:
content = telegramify_markdown.markdownify(
content=component['text'],
)
else:
content = component['text']
args = {
'chat_id': message_source.source_platform_object.effective_chat.id,
'text': content,
}
if self.config['markdown_card'] is True:
args['parse_mode'] = 'MarkdownV2'
if message_source.source_platform_object.message.message_thread_id:
args['message_thread_id'] = message_source.source_platform_object.message.message_thread_id
if quote_origin:
args['reply_to_message_id'] = message_source.source_platform_object.message.id
await self.bot.send_message(**args)
args['text'] = content
await self.bot.send_message(**args)
elif component_type == 'photo':
photo = component.get('photo')
if photo is None:
continue
args['photo'] = telegram.InputFile(photo)
await self.bot.send_photo(**args)
elif component_type == 'document':
doc = component.get('document')
if doc is None:
continue
filename = component.get('filename', 'file')
args['document'] = telegram.InputFile(doc, filename=filename)
await self.bot.send_document(**args)
# ---- Streaming Output (preserving original logic) ----
@@ -310,6 +310,16 @@ class TelegramEventConverter(abstract_platform_adapter.AbstractEventConverter):
source_platform_object=update,
)
if old_status == 'restricted' and new_status in ('member', 'administrator') and mcm.new_chat_member:
return platform_events.BotUnmutedEvent(
type='bot.unmuted',
timestamp=mcm.date.timestamp() if mcm.date else time.time(),
adapter_name='telegram',
group=group,
operator=inviter,
source_platform_object=update,
)
return platform_events.PlatformSpecificEvent(
type='platform.specific',
timestamp=mcm.date.timestamp() if mcm.date else time.time(),
@@ -47,6 +47,9 @@ spec:
- group.member_banned
- bot.invited_to_group
- bot.removed_from_group
- bot.muted
- bot.unmuted
- platform.specific
supported_apis:
required: