mirror of https://github.com/openclaw/openclaw.git
refactor: reduce extension channel setup duplication
This commit is contained in:
parent
74e50d3be3
commit
e885f1999f
|
|
@ -14,10 +14,10 @@ import {
|
|||
deleteAccountFromConfigSection,
|
||||
getChatChannelMeta,
|
||||
PAIRING_APPROVED_MESSAGE,
|
||||
runPassiveAccountLifecycle,
|
||||
setAccountEnabledInConfigSection,
|
||||
type ChannelPlugin,
|
||||
} from "openclaw/plugin-sdk/irc";
|
||||
import { runStoppablePassiveMonitor } from "../../shared/passive-monitor.js";
|
||||
import {
|
||||
listIrcAccountIds,
|
||||
resolveDefaultIrcAccountId,
|
||||
|
|
@ -367,7 +367,7 @@ export const ircPlugin: ChannelPlugin<ResolvedIrcAccount, IrcProbe> = {
|
|||
ctx.log?.info(
|
||||
`[${account.accountId}] starting IRC provider (${account.host}:${account.port}${account.tls ? " tls" : ""})`,
|
||||
);
|
||||
await runPassiveAccountLifecycle({
|
||||
await runStoppablePassiveMonitor({
|
||||
abortSignal: ctx.abortSignal,
|
||||
start: async () =>
|
||||
await monitorIrcProvider({
|
||||
|
|
@ -377,9 +377,6 @@ export const ircPlugin: ChannelPlugin<ResolvedIrcAccount, IrcProbe> = {
|
|||
abortSignal: ctx.abortSignal,
|
||||
statusSink,
|
||||
}),
|
||||
stop: async (monitor) => {
|
||||
monitor.stop();
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -686,6 +686,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
|||
channel: "matrix",
|
||||
accountId: route.accountId,
|
||||
});
|
||||
const humanDelay = core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId);
|
||||
const typingCallbacks = createTypingCallbacks({
|
||||
start: () => sendTypingMatrix(roomId, true, undefined, client),
|
||||
stop: () => sendTypingMatrix(roomId, false, undefined, client),
|
||||
|
|
@ -711,7 +712,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
|||
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||
core.channel.reply.createReplyDispatcherWithTyping({
|
||||
...prefixOptions,
|
||||
humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId),
|
||||
humanDelay,
|
||||
typingCallbacks,
|
||||
deliver: async (payload) => {
|
||||
await deliverMatrixReplies({
|
||||
|
|
|
|||
|
|
@ -475,6 +475,7 @@ async function handleSlashCommandAsync(params: {
|
|||
channel: "mattermost",
|
||||
accountId: account.accountId,
|
||||
});
|
||||
const humanDelay = core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId);
|
||||
|
||||
const typingCallbacks = createTypingCallbacks({
|
||||
start: () => sendMattermostTyping(client, { channelId }),
|
||||
|
|
@ -491,7 +492,7 @@ async function handleSlashCommandAsync(params: {
|
|||
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||
core.channel.reply.createReplyDispatcherWithTyping({
|
||||
...prefixOptions,
|
||||
humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId),
|
||||
humanDelay,
|
||||
deliver: async (payload: ReplyPayload) => {
|
||||
await deliverMattermostReplyPayload({
|
||||
core,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import {
|
|||
createAccountStatusSink,
|
||||
formatAllowFromLowercase,
|
||||
mapAllowFromEntries,
|
||||
runPassiveAccountLifecycle,
|
||||
} from "openclaw/plugin-sdk/compat";
|
||||
import {
|
||||
applyAccountNameToChannelSection,
|
||||
|
|
@ -21,6 +20,7 @@ import {
|
|||
type OpenClawConfig,
|
||||
type ChannelSetupInput,
|
||||
} from "openclaw/plugin-sdk/nextcloud-talk";
|
||||
import { runStoppablePassiveMonitor } from "../../shared/passive-monitor.js";
|
||||
import {
|
||||
listNextcloudTalkAccountIds,
|
||||
resolveDefaultNextcloudTalkAccountId,
|
||||
|
|
@ -344,7 +344,7 @@ export const nextcloudTalkPlugin: ChannelPlugin<ResolvedNextcloudTalkAccount> =
|
|||
setStatus: ctx.setStatus,
|
||||
});
|
||||
|
||||
await runPassiveAccountLifecycle({
|
||||
await runStoppablePassiveMonitor({
|
||||
abortSignal: ctx.abortSignal,
|
||||
start: async () =>
|
||||
await monitorNextcloudTalkProvider({
|
||||
|
|
@ -354,9 +354,6 @@ export const nextcloudTalkPlugin: ChannelPlugin<ResolvedNextcloudTalkAccount> =
|
|||
abortSignal: ctx.abortSignal,
|
||||
statusSink,
|
||||
}),
|
||||
stop: async (monitor) => {
|
||||
monitor.stop();
|
||||
},
|
||||
});
|
||||
},
|
||||
logoutAccount: async ({ accountId, cfg }) => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
import { runPassiveAccountLifecycle } from "openclaw/plugin-sdk";
|
||||
|
||||
type StoppableMonitor = {
|
||||
stop: () => void;
|
||||
};
|
||||
|
||||
export async function runStoppablePassiveMonitor<TMonitor extends StoppableMonitor>(params: {
|
||||
abortSignal: AbortSignal;
|
||||
start: () => Promise<TMonitor>;
|
||||
}): Promise<void> {
|
||||
await runPassiveAccountLifecycle({
|
||||
abortSignal: params.abortSignal,
|
||||
start: params.start,
|
||||
stop: async (monitor) => {
|
||||
monitor.stop();
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue