mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { createChannelMessageAdapterFromOutbound } from "openclaw/plugin-sdk/channel-outbound";
|
|
import type { ChannelOutboundAdapter } from "openclaw/plugin-sdk/channel-send-result";
|
|
import type { matrixChannelRuntime } from "./channel.runtime.js";
|
|
|
|
export function createMatrixMessageAdapter(params: {
|
|
outbound: ChannelOutboundAdapter;
|
|
getRuntime: () => Promise<typeof matrixChannelRuntime>;
|
|
}) {
|
|
const base = createChannelMessageAdapterFromOutbound({
|
|
id: "matrix",
|
|
outbound: params.outbound,
|
|
live: {
|
|
capabilities: {
|
|
draftPreview: true,
|
|
previewFinalization: true,
|
|
progressUpdates: true,
|
|
quietFinalization: true,
|
|
},
|
|
finalizer: {
|
|
capabilities: {
|
|
finalEdit: true,
|
|
normalFallback: true,
|
|
discardPending: true,
|
|
previewReceipt: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return {
|
|
...base,
|
|
durableFinal: {
|
|
...base.durableFinal,
|
|
automaticUnknownSendReconciliation: true,
|
|
capabilities: {
|
|
...base.durableFinal?.capabilities,
|
|
afterCommit: true,
|
|
reconcileUnknownSend: true,
|
|
},
|
|
reconcileUnknownSendKinds: { text: true, media: true },
|
|
reconcileUnknownSend: async (ctx) =>
|
|
await (await params.getRuntime()).reconcileMatrixUnknownSend(ctx),
|
|
afterUnknownSendTerminal: async (ctx) =>
|
|
await (await params.getRuntime()).cleanupMatrixDeliveryPlans({ queueId: ctx.queueId }),
|
|
},
|
|
send: {
|
|
...base.send,
|
|
lifecycle: {
|
|
afterCommit: async (ctx) => {
|
|
if (!ctx.deliveryQueueId) {
|
|
return;
|
|
}
|
|
await (
|
|
await params.getRuntime()
|
|
).cleanupMatrixDeliveryPlans({
|
|
queueId: ctx.deliveryQueueId,
|
|
});
|
|
},
|
|
},
|
|
},
|
|
} satisfies typeof base;
|
|
}
|