Skip to content

Commit

Permalink
print out debug message for Direct message flow
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Jan 21, 2024
1 parent dd0942f commit 709a4c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ 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,
});
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);
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/init/customRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down

0 comments on commit 709a4c3

Please sign in to comment.