@@ -10,14 +10,17 @@ export default async function invoke(
1010 _req : Request ,
1111 ctx : AppContext ,
1212) {
13- console . log ( "slack request" , { props } ) ;
1413 const challenge = props . challenge ;
1514 if ( challenge ) {
1615 return { challenge } ;
1716 }
17+
18+ const [ channel , thread ] = props . type === "event_callback"
19+ ? [ props . event . user , props . event . channel ]
20+ : [ props . event . channel , props . event . channel ] ;
1821 const linkProps =
1922 await ctx . appStorage . getItem < JoinChannelProps & { installId : string } > (
20- ctx . cb . forTeam ( props . event . team , props . event . channel ) ,
23+ ctx . cb . forTeam ( props . event . team , channel ) ,
2124 ) ??
2225 undefined ;
2326 if ( ! linkProps ) {
@@ -40,7 +43,7 @@ export default async function invoke(
4043 const streamURL = new URL ( streamCallbackUrl ) ;
4144 streamURL . searchParams . set (
4245 "__d" ,
43- `slack-${ props . event . team } -${ props . event . channel } ` ,
46+ `slack-${ props . event . team } -${ channel } ` ,
4447 ) ;
4548 const toolCallMessageTs : Record <
4649 string ,
@@ -55,8 +58,8 @@ export default async function invoke(
5558 role : "user" ,
5659 } ] ,
5760 options : {
58- threadId : props . event . channel ,
59- resourceId : props . event . channel ,
61+ threadId : thread ,
62+ resourceId : thread ,
6063 } ,
6164 } ,
6265 onToolCallPart : async ( toolCall ) => {
@@ -92,7 +95,7 @@ export default async function invoke(
9295 ] ,
9396 } ,
9497 ] ;
95- const response = await client . postMessage ( props . event . channel , "" , {
98+ const response = await client . postMessage ( channel , "" , {
9699 thread_ts : props . event . ts ,
97100 blocks,
98101 } ) ;
@@ -153,7 +156,7 @@ export default async function invoke(
153156 ] ,
154157 } ,
155158 ] ;
156- await client . updateMessage ( props . event . channel , call . ts , "" , {
159+ await client . updateMessage ( channel , call . ts , "" , {
157160 blocks,
158161 } ) ;
159162 }
@@ -162,15 +165,15 @@ export default async function invoke(
162165 buffer += part ;
163166 } ,
164167 onErrorPart : async ( err : string ) => {
165- await client . postMessage ( props . event . channel , `❌ Error: ${ err } ` , {
168+ await client . postMessage ( channel , `❌ Error: ${ err } ` , {
166169 thread_ts : props . event . ts ,
167170 } ) ;
168171 } ,
169172 onFinishMessagePart : async ( ) => {
170173 if ( linkProps . agentLink && linkProps . agentName ) {
171174 buffer = `<${ linkProps . agentLink } |${ linkProps . agentName } >: ${ buffer } ` ;
172175 }
173- await client . postMessage ( props . event . channel , buffer , {
176+ await client . postMessage ( channel , buffer , {
174177 thread_ts : props . event . ts ,
175178 } ) . then ( ( response ) => {
176179 if ( ! response . ok ) {
0 commit comments