mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(outbound): reuse message gateway call
This commit is contained in:
@@ -124,6 +124,24 @@ function resolveGatewayOptions(opts?: MessageGatewayOptions) {
|
||||
};
|
||||
}
|
||||
|
||||
async function callMessageGateway<T>(params: {
|
||||
gateway?: MessageGatewayOptions;
|
||||
method: string;
|
||||
params: Record<string, unknown>;
|
||||
}): Promise<T> {
|
||||
const gateway = resolveGatewayOptions(params.gateway);
|
||||
return await callGateway<T>({
|
||||
url: gateway.url,
|
||||
token: gateway.token,
|
||||
method: params.method,
|
||||
params: params.params,
|
||||
timeoutMs: gateway.timeoutMs,
|
||||
clientName: gateway.clientName,
|
||||
clientDisplayName: gateway.clientDisplayName,
|
||||
mode: gateway.mode,
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendMessage(params: MessageSendParams): Promise<MessageSendResult> {
|
||||
const cfg = params.cfg ?? loadConfig();
|
||||
const channel = params.channel?.trim()
|
||||
@@ -210,10 +228,8 @@ export async function sendMessage(params: MessageSendParams): Promise<MessageSen
|
||||
};
|
||||
}
|
||||
|
||||
const gateway = resolveGatewayOptions(params.gateway);
|
||||
const result = await callGateway<{ messageId: string }>({
|
||||
url: gateway.url,
|
||||
token: gateway.token,
|
||||
const result = await callMessageGateway<{ messageId: string }>({
|
||||
gateway: params.gateway,
|
||||
method: "send",
|
||||
params: {
|
||||
to: params.to,
|
||||
@@ -226,10 +242,6 @@ export async function sendMessage(params: MessageSendParams): Promise<MessageSen
|
||||
sessionKey: params.mirror?.sessionKey,
|
||||
idempotencyKey: params.idempotencyKey ?? randomIdempotencyKey(),
|
||||
},
|
||||
timeoutMs: gateway.timeoutMs,
|
||||
clientName: gateway.clientName,
|
||||
clientDisplayName: gateway.clientDisplayName,
|
||||
mode: gateway.mode,
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -281,16 +293,14 @@ export async function sendPoll(params: MessagePollParams): Promise<MessagePollRe
|
||||
};
|
||||
}
|
||||
|
||||
const gateway = resolveGatewayOptions(params.gateway);
|
||||
const result = await callGateway<{
|
||||
const result = await callMessageGateway<{
|
||||
messageId: string;
|
||||
toJid?: string;
|
||||
channelId?: string;
|
||||
conversationId?: string;
|
||||
pollId?: string;
|
||||
}>({
|
||||
url: gateway.url,
|
||||
token: gateway.token,
|
||||
gateway: params.gateway,
|
||||
method: "poll",
|
||||
params: {
|
||||
to: params.to,
|
||||
@@ -306,10 +316,6 @@ export async function sendPoll(params: MessagePollParams): Promise<MessagePollRe
|
||||
accountId: params.accountId,
|
||||
idempotencyKey: params.idempotencyKey ?? randomIdempotencyKey(),
|
||||
},
|
||||
timeoutMs: gateway.timeoutMs,
|
||||
clientName: gateway.clientName,
|
||||
clientDisplayName: gateway.clientDisplayName,
|
||||
mode: gateway.mode,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user