diff --git a/extensions/bluebubbles/src/channel.ts b/extensions/bluebubbles/src/channel.ts index 25d47aafd93..0400fa5bd67 100644 --- a/extensions/bluebubbles/src/channel.ts +++ b/extensions/bluebubbles/src/channel.ts @@ -29,6 +29,7 @@ import { DEFAULT_ACCOUNT_ID, PAIRING_APPROVED_MESSAGE, } from "./runtime-api.js"; +import { resolveBlueBubblesOutboundSessionRoute } from "./session-route.js"; import { blueBubblesSetupAdapter } from "./setup-core.js"; import { blueBubblesSetupWizard } from "./setup-surface.js"; import { @@ -140,6 +141,7 @@ export const bluebubblesPlugin: ChannelPlugin = { }, messaging: { normalizeTarget: normalizeBlueBubblesMessagingTarget, + resolveOutboundSessionRoute: (params) => resolveBlueBubblesOutboundSessionRoute(params), targetResolver: { looksLikeId: looksLikeBlueBubblesTargetId, hint: "", diff --git a/extensions/bluebubbles/src/session-route.ts b/extensions/bluebubbles/src/session-route.ts new file mode 100644 index 00000000000..a889887a4bd --- /dev/null +++ b/extensions/bluebubbles/src/session-route.ts @@ -0,0 +1,37 @@ +import { + buildChannelOutboundSessionRoute, + stripChannelTargetPrefix, + type ChannelOutboundSessionRouteParams, +} from "openclaw/plugin-sdk/core"; +import { parseBlueBubblesTarget } from "./targets.js"; + +export function resolveBlueBubblesOutboundSessionRoute(params: ChannelOutboundSessionRouteParams) { + const stripped = stripChannelTargetPrefix(params.target, "bluebubbles"); + if (!stripped) { + return null; + } + const parsed = parseBlueBubblesTarget(stripped); + const isGroup = + parsed.kind === "chat_id" || parsed.kind === "chat_guid" || parsed.kind === "chat_identifier"; + const peerId = + parsed.kind === "chat_id" + ? String(parsed.chatId) + : parsed.kind === "chat_guid" + ? parsed.chatGuid + : parsed.kind === "chat_identifier" + ? parsed.chatIdentifier + : parsed.to; + return buildChannelOutboundSessionRoute({ + cfg: params.cfg, + agentId: params.agentId, + channel: "bluebubbles", + accountId: params.accountId, + peer: { + kind: isGroup ? "group" : "direct", + id: peerId, + }, + chatType: isGroup ? "group" : "direct", + from: isGroup ? `group:${peerId}` : `bluebubbles:${peerId}`, + to: `bluebubbles:${stripped}`, + }); +}