mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:10:49 +00:00
Fix Matrix approval metadata delivery fallback
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
811653a875
commit
41fc2872a1
@@ -71,6 +71,7 @@ type MatrixPrepareTargetParams = {
|
||||
export type MatrixApprovalHandlerDeps = {
|
||||
nowMs?: () => number;
|
||||
sendMessage?: typeof sendMessageMatrix;
|
||||
sendSingleTextMessage?: typeof sendSingleTextMessageMatrix;
|
||||
reactMessage?: typeof reactMatrixMessage;
|
||||
editMessage?: typeof editMatrixMessage;
|
||||
deleteMessage?: typeof deleteMatrixMessage;
|
||||
@@ -112,6 +113,10 @@ function normalizeThreadId(value?: string | number | null): string | undefined {
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
function isSingleMatrixMessageLimitError(error: unknown): boolean {
|
||||
return error instanceof Error && error.message.includes("Matrix single-message text exceeds limit");
|
||||
}
|
||||
|
||||
async function prepareTarget(
|
||||
params: MatrixPrepareTargetParams,
|
||||
): Promise<PreparedMatrixTarget | null> {
|
||||
@@ -355,22 +360,30 @@ export const matrixApprovalNativeRuntime = createChannelApprovalNativeRuntimeAda
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
const sendMessage = resolved.context.deps?.sendMessage;
|
||||
const sendSingleTextMessage =
|
||||
resolved.context.deps?.sendSingleTextMessage ?? sendSingleTextMessageMatrix;
|
||||
const reactMessage = resolved.context.deps?.reactMessage ?? reactMatrixMessage;
|
||||
const result = sendMessage
|
||||
? await sendMessage(preparedTarget.to, pendingPayload.text, {
|
||||
cfg: cfg as CoreConfig,
|
||||
accountId: resolved.accountId,
|
||||
client: resolved.context.client,
|
||||
threadId: preparedTarget.threadId,
|
||||
})
|
||||
: await sendSingleTextMessageMatrix(preparedTarget.to, pendingPayload.text, {
|
||||
cfg: cfg as CoreConfig,
|
||||
accountId: resolved.accountId,
|
||||
client: resolved.context.client,
|
||||
threadId: preparedTarget.threadId,
|
||||
extraContent: pendingPayload.extraContent,
|
||||
});
|
||||
let result;
|
||||
try {
|
||||
result = await sendSingleTextMessage(preparedTarget.to, pendingPayload.text, {
|
||||
cfg: cfg as CoreConfig,
|
||||
accountId: resolved.accountId,
|
||||
client: resolved.context.client,
|
||||
threadId: preparedTarget.threadId,
|
||||
extraContent: pendingPayload.extraContent,
|
||||
});
|
||||
} catch (error) {
|
||||
if (!isSingleMatrixMessageLimitError(error)) {
|
||||
throw error;
|
||||
}
|
||||
const sendMessage = resolved.context.deps?.sendMessage ?? sendMessageMatrix;
|
||||
result = await sendMessage(preparedTarget.to, pendingPayload.text, {
|
||||
cfg: cfg as CoreConfig,
|
||||
accountId: resolved.accountId,
|
||||
client: resolved.context.client,
|
||||
threadId: preparedTarget.threadId,
|
||||
});
|
||||
}
|
||||
const messageIds = Array.from(
|
||||
new Set(
|
||||
(result.messageIds ?? [result.messageId])
|
||||
|
||||
Reference in New Issue
Block a user