MCPcopy
hub / github.com/simstudioai/sim / sendSlackMessage

Function sendSlackMessage

apps/sim/app/api/tools/slack/utils.ts:249–343  ·  view source on GitHub ↗
(
  params: SlackMessageParams,
  requestId: string,
  logger: Logger
)

Source from the content-addressed store, hash-verified

247 * Supports both channel messages and direct messages via userId
248 */
249export async function sendSlackMessage(
250 params: SlackMessageParams,
251 requestId: string,
252 logger: Logger
253): Promise<{
254 success: boolean
255 output?: {
256 message: any
257 ts: string
258 channel: string
259 fileCount?: number
260 files?: ToolFileData[]
261 }
262 error?: string
263}> {
264 const { accessToken, text, threadTs, blocks, files, ownerUserId } = params
265 let { channel } = params
266
267 if (!channel && params.userId) {
268 logger.info(`[${requestId}] Opening DM channel for user: ${params.userId}`)
269 channel = await openDMChannel(accessToken, params.userId, requestId, logger)
270 }
271
272 if (!channel) {
273 return { success: false, error: 'Either channel or userId is required' }
274 }
275
276 // No files - simple message
277 if (!files || files.length === 0) {
278 logger.info(`[${requestId}] No files, using chat.postMessage`)
279
280 const data = await postSlackMessage(accessToken, channel, text, threadTs, blocks)
281
282 if (!data.ok) {
283 logger.error(`[${requestId}] Slack API error:`, data.error)
284 return { success: false, error: data.error || 'Failed to send message' }
285 }
286
287 logger.info(`[${requestId}] Message sent successfully`)
288 return { success: true, output: formatMessageSuccessResponse(data, text) }
289 }
290
291 // Process files
292 logger.info(`[${requestId}] Processing ${files.length} file(s)`)
293 const { fileIds, files: uploadedFiles } = await uploadFilesToSlack(
294 files,
295 accessToken,
296 requestId,
297 logger,
298 ownerUserId
299 )
300
301 // No valid files uploaded - send text-only
302 if (fileIds.length === 0) {
303 logger.warn(`[${requestId}] No valid files to upload, sending text-only message`)
304
305 const data = await postSlackMessage(accessToken, channel, text, threadTs, blocks)
306

Callers 1

route.tsFile · 0.90

Calls 9

openDMChannelFunction · 0.85
postSlackMessageFunction · 0.85
uploadFilesToSlackFunction · 0.85
completeSlackFileUploadFunction · 0.85
createFileMessageObjectFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected