@@ -36,6 +36,7 @@ import {
3636 resolveDefaultSlackAccountId ,
3737 resolveSlackAccount ,
3838 resolveSlackAccountAllowFrom ,
39+ resolveSlackOperationToken ,
3940 resolveSlackReplyToMode ,
4041 type ResolvedSlackAccount ,
4142} from "./accounts.js" ;
@@ -160,23 +161,6 @@ function shouldTreatSlackDeliveredTextAsVisible(params: {
160161 ) ;
161162}
162163
163- // Select the appropriate Slack token for read/write operations.
164- function getTokenForOperation (
165- account : ResolvedSlackAccount ,
166- operation : "read" | "write" ,
167- ) : string | undefined {
168- const userToken = normalizeOptionalString ( account . userToken ) ;
169- const botToken = normalizeOptionalString ( account . botToken ) ;
170- const allowUserWrites = account . config . userTokenReadOnly === false ;
171- if ( operation === "read" ) {
172- return userToken ?? botToken ;
173- }
174- if ( ! allowUserWrites ) {
175- return botToken ;
176- }
177- return botToken ?? userToken ;
178- }
179-
180164type SlackSendFn = typeof import ( "./send.runtime.js" ) . sendMessageSlack ;
181165
182166const loadSlackDirectoryConfigModule = createLazyRuntimeModule (
@@ -211,7 +195,7 @@ async function resolveSlackSendContext(params: {
211195 // expected to be resolved from this snapshot. Strict mode
212196 // is intentional so boot-time misconfigurations surface loudly. See #68237.
213197 const account = resolveSlackAccount ( { cfg : params . cfg , accountId : params . accountId } ) ;
214- const token = getTokenForOperation ( account , "write" ) ;
198+ const token = resolveSlackOperationToken ( account , "write" ) ;
215199 const botToken = account . botToken ?. trim ( ) ;
216200 const tokenOverride = token && token !== botToken ? token : undefined ;
217201 const threadTsValue = resolveSlackThreadTsValue ( params ) ;
@@ -263,6 +247,8 @@ function withSlackSendOverride(params: {
263247 deps ?: { [ channelId : string ] : unknown } | null ;
264248 send : SlackSendFn ;
265249 tokenOverride ?: string ;
250+ deliveryQueueId ?: string ;
251+ onPlatformSendDispatch ?: ( ) => Promise < void > ;
266252} ) {
267253 return {
268254 ...params . deps ,
@@ -274,6 +260,10 @@ function withSlackSendOverride(params: {
274260 await params . send ( to , text , {
275261 ...opts ,
276262 ...( params . tokenOverride ? { token : params . tokenOverride } : { } ) ,
263+ ...( params . deliveryQueueId ? { deliveryQueueId : params . deliveryQueueId } : { } ) ,
264+ ...( params . onPlatformSendDispatch
265+ ? { onPlatformSendDispatch : params . onPlatformSendDispatch }
266+ : { } ) ,
277267 } ) ,
278268 } ;
279269}
@@ -510,7 +500,13 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
510500 ...ctx ,
511501 replyToId : threadTsValue ,
512502 threadId : null ,
513- deps : withSlackSendOverride ( { deps : ctx . deps , send, tokenOverride } ) ,
503+ deliveryQueueId : undefined ,
504+ onPlatformSendDispatch : undefined ,
505+ deps : withSlackSendOverride ( {
506+ deps : ctx . deps ,
507+ send,
508+ tokenOverride,
509+ } ) ,
514510 } ) ;
515511 } ,
516512 sendText : async ( ctx ) => {
@@ -526,7 +522,15 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
526522 ...ctx ,
527523 replyToId : threadTsValue ,
528524 threadId : null ,
529- deps : withSlackSendOverride ( { deps : ctx . deps , send, tokenOverride } ) ,
525+ deliveryQueueId : undefined ,
526+ onPlatformSendDispatch : undefined ,
527+ deps : withSlackSendOverride ( {
528+ deps : ctx . deps ,
529+ send,
530+ tokenOverride,
531+ deliveryQueueId : ctx . deliveryQueueId ,
532+ onPlatformSendDispatch : ctx . onPlatformSendDispatch ,
533+ } ) ,
530534 } ) ;
531535 } ,
532536 sendMedia : async ( ctx ) => {
@@ -542,12 +546,18 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
542546 ...ctx ,
543547 replyToId : threadTsValue ,
544548 threadId : null ,
545- deps : withSlackSendOverride ( { deps : ctx . deps , send, tokenOverride } ) ,
549+ deliveryQueueId : undefined ,
550+ onPlatformSendDispatch : undefined ,
551+ deps : withSlackSendOverride ( {
552+ deps : ctx . deps ,
553+ send,
554+ tokenOverride,
555+ } ) ,
546556 } ) ;
547557 } ,
548558} ;
549559
550- const slackMessageAdapter = createChannelMessageAdapterFromOutbound ( {
560+ const slackMessageAdapterBase = createChannelMessageAdapterFromOutbound ( {
551561 id : "slack" ,
552562 outbound : slackChannelOutbound ,
553563 live : {
@@ -567,6 +577,19 @@ const slackMessageAdapter = createChannelMessageAdapterFromOutbound({
567577 } ,
568578} ) ;
569579
580+ const slackMessageAdapter = {
581+ ...slackMessageAdapterBase ,
582+ durableFinal : {
583+ capabilities : {
584+ ...slackMessageAdapterBase . durableFinal ?. capabilities ,
585+ reconcileUnknownSend : true ,
586+ } ,
587+ reconcileUnknownSendKinds : { text : true } ,
588+ reconcileUnknownSend : async ( ctx ) =>
589+ await ( await loadSlackSendRuntime ( ) ) . reconcileSlackUnknownSend ( ctx ) ,
590+ } ,
591+ } satisfies typeof slackMessageAdapterBase ;
592+
570593export const slackPlugin : ChannelPlugin < ResolvedSlackAccount , SlackProbe > = createChatChannelPlugin <
571594 ResolvedSlackAccount ,
572595 SlackProbe
@@ -844,7 +867,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
844867 accountId : resolveDefaultSlackAccountId ( cfg ) ,
845868 } ) ;
846869 const { sendMessageSlack } = await loadSlackSendRuntime ( ) ;
847- const token = getTokenForOperation ( account , "write" ) ;
870+ const token = resolveSlackOperationToken ( account , "write" ) ;
848871 await sendMessageSlack ( `user:${ id } ` , message , {
849872 cfg,
850873 accountId : account . accountId ,
0 commit comments