diff --git a/src/index.ts b/src/index.ts index 2a2af58..50ab375 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,6 +115,7 @@ app.view('mermaid-modal-submitted', async ({ ack, body, logger, client }) => { // Check for direct message if (origin.channel.startsWith('D')) { + logger.info('Direct message detected'); try { const userChannel = await client.conversations.open({ users: origin.user_id, @@ -122,6 +123,8 @@ app.view('mermaid-modal-submitted', async ({ ack, body, logger, client }) => { channelToUpload = userChannel.channel?.id ? userChannel.channel.id : channelToUpload; + logger.info('User channel', userChannel); + logger.info('Channel selected', channelToUpload); } catch (error) { logger.error('Failed to open an user channel, but continuing', error); } @@ -170,6 +173,28 @@ app.view('mermaid-modal-submitted', async ({ ack, body, logger, client }) => { title: 'Mermaid diagram', }); + if (channelToUpload.startsWith('D')) { + const diagramUploadYolo = await client.files.upload({ + channels: origin.user_id, + file: fs.createReadStream(outputPath), + filename: 'mermaid.png', + initial_comment: `<@${origin.user_id}> created this Mermaid diagram:`, + title: 'Mermaid diagram', + }); + const diagramUploadYolov2 = await client.files.upload({ + channels: origin.channel, + file: fs.createReadStream(outputPath), + filename: 'mermaid.png', + initial_comment: `<@${origin.user_id}> created this Mermaid diagram:`, + title: 'Mermaid diagram', + }); + console.log(diagramUploadYolo, diagramUploadYolov2); + console.log( + JSON.stringify(diagramUploadYolo, null, ' '), + JSON.stringify(diagramUploadYolov2, null, ' ') + ); + } + if (diagramUpload.file?.shares) { const shareKeys = Object.keys(diagramUpload.file.shares); for (const shareType of shareKeys) { diff --git a/src/init/customRoutes.ts b/src/init/customRoutes.ts index f784a50..86dcb0c 100644 --- a/src/init/customRoutes.ts +++ b/src/init/customRoutes.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { type CustomRoute } from '@slack/bolt'; const indexHTML = fs.readFileSync( - path.resolve(__dirname, '../public/index.html') + path.resolve(__dirname, '../../public/index.html') ); const customRoutes: CustomRoute[] = [