mirror of https://github.com/openclaw/openclaw.git
refactor: deduplicate nextcloud send context
This commit is contained in:
parent
6b07604d64
commit
a4525b721e
|
|
@ -42,11 +42,12 @@ function normalizeRoomToken(to: string): string {
|
||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendMessageNextcloudTalk(
|
function resolveNextcloudTalkSendContext(opts: NextcloudTalkSendOpts): {
|
||||||
to: string,
|
cfg: CoreConfig;
|
||||||
text: string,
|
account: ReturnType<typeof resolveNextcloudTalkAccount>;
|
||||||
opts: NextcloudTalkSendOpts = {},
|
baseUrl: string;
|
||||||
): Promise<NextcloudTalkSendResult> {
|
secret: string;
|
||||||
|
} {
|
||||||
const cfg = (opts.cfg ?? getNextcloudTalkRuntime().config.loadConfig()) as CoreConfig;
|
const cfg = (opts.cfg ?? getNextcloudTalkRuntime().config.loadConfig()) as CoreConfig;
|
||||||
const account = resolveNextcloudTalkAccount({
|
const account = resolveNextcloudTalkAccount({
|
||||||
cfg,
|
cfg,
|
||||||
|
|
@ -56,6 +57,15 @@ export async function sendMessageNextcloudTalk(
|
||||||
{ baseUrl: opts.baseUrl, secret: opts.secret },
|
{ baseUrl: opts.baseUrl, secret: opts.secret },
|
||||||
account,
|
account,
|
||||||
);
|
);
|
||||||
|
return { cfg, account, baseUrl, secret };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function sendMessageNextcloudTalk(
|
||||||
|
to: string,
|
||||||
|
text: string,
|
||||||
|
opts: NextcloudTalkSendOpts = {},
|
||||||
|
): Promise<NextcloudTalkSendResult> {
|
||||||
|
const { cfg, account, baseUrl, secret } = resolveNextcloudTalkSendContext(opts);
|
||||||
const roomToken = normalizeRoomToken(to);
|
const roomToken = normalizeRoomToken(to);
|
||||||
|
|
||||||
if (!text?.trim()) {
|
if (!text?.trim()) {
|
||||||
|
|
@ -162,15 +172,7 @@ export async function sendReactionNextcloudTalk(
|
||||||
reaction: string,
|
reaction: string,
|
||||||
opts: Omit<NextcloudTalkSendOpts, "replyTo"> = {},
|
opts: Omit<NextcloudTalkSendOpts, "replyTo"> = {},
|
||||||
): Promise<{ ok: true }> {
|
): Promise<{ ok: true }> {
|
||||||
const cfg = (opts.cfg ?? getNextcloudTalkRuntime().config.loadConfig()) as CoreConfig;
|
const { account, baseUrl, secret } = resolveNextcloudTalkSendContext(opts);
|
||||||
const account = resolveNextcloudTalkAccount({
|
|
||||||
cfg,
|
|
||||||
accountId: opts.accountId,
|
|
||||||
});
|
|
||||||
const { baseUrl, secret } = resolveCredentials(
|
|
||||||
{ baseUrl: opts.baseUrl, secret: opts.secret },
|
|
||||||
account,
|
|
||||||
);
|
|
||||||
const normalizedToken = normalizeRoomToken(roomToken);
|
const normalizedToken = normalizeRoomToken(roomToken);
|
||||||
|
|
||||||
const body = JSON.stringify({ reaction });
|
const body = JSON.stringify({ reaction });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue