From 4ab25a2889e01ade62322ff9e6b636a43a16574c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 00:56:21 +0000 Subject: [PATCH] refactor(outbound): reuse message gateway call --- src/infra/outbound/message.ts | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/infra/outbound/message.ts b/src/infra/outbound/message.ts index 4170d88ffc6..bf013f7a15b 100644 --- a/src/infra/outbound/message.ts +++ b/src/infra/outbound/message.ts @@ -124,6 +124,24 @@ function resolveGatewayOptions(opts?: MessageGatewayOptions) { }; } +async function callMessageGateway(params: { + gateway?: MessageGatewayOptions; + method: string; + params: Record; +}): Promise { + const gateway = resolveGatewayOptions(params.gateway); + return await callGateway({ + 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 { const cfg = params.cfg ?? loadConfig(); const channel = params.channel?.trim() @@ -210,10 +228,8 @@ export async function sendMessage(params: MessageSendParams): Promise({ - 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({ - 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