@@ -36,7 +36,7 @@ import {
3636 resolveSlackReplyToMode ,
3737 type ResolvedSlackAccount ,
3838} from "./accounts.js" ;
39- import { handleSlackAction , type SlackActionContext } from "./action-runtime.js" ;
39+ import type { SlackActionContext } from "./action-runtime.js" ;
4040import { resolveSlackAutoThreadId } from "./action-threading.js" ;
4141import { slackApprovalCapability } from "./approval-native.js" ;
4242import { createSlackActions } from "./channel-actions.js" ;
@@ -69,7 +69,6 @@ import {
6969import { getOptionalSlackRuntime , getSlackRuntime } from "./runtime.js" ;
7070import { fetchSlackScopes } from "./scopes.js" ;
7171import { collectSlackSecurityAuditFindings } from "./security-audit.js" ;
72- import { sendMessageSlack } from "./send.js" ;
7372import { slackSetupAdapter } from "./setup-core.js" ;
7473import { slackSetupWizard } from "./setup-surface.js" ;
7574import {
@@ -97,8 +96,11 @@ function resolveSlackProbe() {
9796 return probeSlack ;
9897}
9998
100- function resolveSlackHandleAction ( ) {
101- return getOptionalSlackRuntime ( ) ?. channel ?. slack ?. handleSlackAction ?? handleSlackAction ;
99+ async function resolveSlackHandleAction ( ) {
100+ return (
101+ getOptionalSlackRuntime ( ) ?. channel ?. slack ?. handleSlackAction ??
102+ ( await loadSlackActionRuntime ( ) ) . handleSlackAction
103+ ) ;
102104}
103105
104106// Select the appropriate Slack token for read/write operations.
@@ -118,16 +120,31 @@ function getTokenForOperation(
118120 return botToken ?? userToken ;
119121}
120122
121- type SlackSendFn = typeof sendMessageSlack ;
123+ type SlackSendFn = typeof import ( "./send.runtime.js" ) . sendMessageSlack ;
122124
123- function resolveSlackSendContext ( params : {
125+ let slackActionRuntimePromise : Promise < typeof import ( "./action-runtime.runtime.js" ) > | undefined ;
126+ let slackSendRuntimePromise : Promise < typeof import ( "./send.runtime.js" ) > | undefined ;
127+
128+ async function loadSlackActionRuntime ( ) {
129+ slackActionRuntimePromise ??= import ( "./action-runtime.runtime.js" ) ;
130+ return await slackActionRuntimePromise ;
131+ }
132+
133+ async function loadSlackSendRuntime ( ) {
134+ slackSendRuntimePromise ??= import ( "./send.runtime.js" ) ;
135+ return await slackSendRuntimePromise ;
136+ }
137+
138+ async function resolveSlackSendContext ( params : {
124139 cfg : Parameters < typeof resolveSlackAccount > [ 0 ] [ "cfg" ] ;
125140 accountId ?: string ;
126141 deps ?: { [ channelId : string ] : unknown } ;
127142 replyToId ?: string | number | null ;
128143 threadId ?: string | number | null ;
129144} ) {
130- const send = resolveOutboundSendDep < SlackSendFn > ( params . deps , "slack" ) ?? sendMessageSlack ;
145+ const send =
146+ resolveOutboundSendDep < SlackSendFn > ( params . deps , "slack" ) ??
147+ ( await loadSlackSendRuntime ( ) ) . sendMessageSlack ;
131148 const account = resolveSlackAccount ( { cfg : params . cfg , accountId : params . accountId } ) ;
132149 const token = getTokenForOperation ( account , "write" ) ;
133150 const botToken = account . botToken ?. trim ( ) ;
@@ -369,11 +386,9 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
369386 } ,
370387 actions : createSlackActions ( SLACK_CHANNEL , {
371388 invoke : async ( action , cfg , toolContext ) =>
372- await resolveSlackHandleAction ( ) (
373- action ,
374- cfg as OpenClawConfig ,
375- toolContext as SlackActionContext | undefined ,
376- ) ,
389+ await (
390+ await resolveSlackHandleAction ( )
391+ ) ( action , cfg as OpenClawConfig , toolContext as SlackActionContext | undefined ) ,
377392 } ) ,
378393 status : createComputedAccountStatusAdapter < ResolvedSlackAccount , SlackProbe > ( {
379394 defaultRuntime : createDefaultChannelRuntimeState ( DEFAULT_ACCOUNT_ID ) ,
@@ -476,6 +491,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
476491 cfg,
477492 accountId : DEFAULT_ACCOUNT_ID ,
478493 } ) ;
494+ const { sendMessageSlack } = await loadSlackSendRuntime ( ) ;
479495 const token = getTokenForOperation ( account , "write" ) ;
480496 const botToken = account . botToken ?. trim ( ) ;
481497 const tokenOverride = token && token !== botToken ? token : undefined ;
@@ -525,7 +541,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
525541 payload,
526542 } ) ,
527543 sendPayload : async ( ctx ) => {
528- const { send, tokenOverride } = resolveSlackSendContext ( {
544+ const { send, tokenOverride } = await resolveSlackSendContext ( {
529545 cfg : ctx . cfg ,
530546 accountId : ctx . accountId ?? undefined ,
531547 deps : ctx . deps ,
@@ -552,7 +568,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
552568 attachedResults : {
553569 channel : "slack" ,
554570 sendText : async ( { to, text, accountId, deps, replyToId, threadId, cfg } ) => {
555- const { send, threadTsValue, tokenOverride } = resolveSlackSendContext ( {
571+ const { send, threadTsValue, tokenOverride } = await resolveSlackSendContext ( {
556572 cfg,
557573 accountId : accountId ?? undefined ,
558574 deps,
@@ -577,7 +593,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
577593 threadId,
578594 cfg,
579595 } ) => {
580- const { send, threadTsValue, tokenOverride } = resolveSlackSendContext ( {
596+ const { send, threadTsValue, tokenOverride } = await resolveSlackSendContext ( {
581597 cfg,
582598 accountId : accountId ?? undefined ,
583599 deps,
0 commit comments