新增小红书、XMPP、元宝、Zalo 四个渠道扩展。 小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor 元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from yuxi.channel.extensions.xmpp.types import InboundXmppMessage, ResolvedXmppAccount
|
|
from yuxi.channel.message.models import GroupContext, MessageType, PeerInfo, UnifiedMessage
|
|
from yuxi.channel.routing.models import PeerKind
|
|
|
|
|
|
def xmpp_stanza_to_unified(
|
|
inbound: InboundXmppMessage,
|
|
account: ResolvedXmppAccount,
|
|
) -> UnifiedMessage:
|
|
is_group = inbound.msg_type == "groupchat"
|
|
peer_kind = PeerKind.GROUP if is_group else PeerKind.DIRECT
|
|
|
|
sender = PeerInfo(
|
|
kind=peer_kind,
|
|
id=inbound.from_bare,
|
|
display_name=inbound.muc_nick or inbound.from_bare,
|
|
)
|
|
|
|
group = None
|
|
if is_group and inbound.room_jid:
|
|
group = GroupContext(id=inbound.room_jid, name=inbound.room_jid)
|
|
|
|
target_id = inbound.room_jid if is_group else inbound.from_bare
|
|
|
|
return UnifiedMessage(
|
|
msg_id=inbound.stanza_id or inbound.msg_id,
|
|
channel_type="xmpp",
|
|
account_id=account.account_id,
|
|
content=inbound.body,
|
|
sender=sender,
|
|
message_type=MessageType.TEXT,
|
|
group=group,
|
|
timestamp=inbound.timestamp,
|
|
raw_payload=inbound.raw,
|
|
metadata={
|
|
"room_jid": inbound.room_jid,
|
|
"muc_nick": inbound.muc_nick,
|
|
"thread_id": inbound.thread_id,
|
|
"was_mentioned": inbound.mentions_bot,
|
|
"target_id": target_id,
|
|
},
|
|
conversation_label=inbound.muc_nick if is_group else inbound.from_bare,
|
|
surface="xmpp",
|
|
originating_channel="xmpp",
|
|
)
|