Skip to content

Commit

Permalink
refactor: Add in slackbot pdfssssssssssssssssssssssssssssssssssss
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-map committed Oct 5, 2024
1 parent 9a44679 commit 5dac1c3
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/bot/requestReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ActionId, Deadline, DeadlineLabel, Interaction } from './enums';
import { chatService } from '@/services/ChatService';
import { determineExpirationTime } from '@utils/reviewExpirationUtils';
import { putPdfToS3 } from '@utils/s3';
import { Stream } from 'stream';

export const requestReview = {
app: undefined as unknown as App,
Expand Down Expand Up @@ -110,20 +111,20 @@ export const requestReview = {
},
},
},
// {
// type: 'input',
// block_id: ActionId.PDF_IDENTIFIER,
// label: {
// text: 'Input PDF File',
// type: 'plain_text',
// },
// element: {
// type: 'file_input',
// action_id: ActionId.PDF_IDENTIFIER,
// max_files: 1,
// filetypes: ['pdf'],
// },
// },
{
type: 'input',
block_id: ActionId.PDF_IDENTIFIER,
label: {
text: 'Input PDF File',
type: 'plain_text',
},
element: {
type: 'file_input',
action_id: ActionId.PDF_IDENTIFIER,
max_files: 1,
filetypes: ['pdf'],
},
},
],
submit: {
type: 'plain_text',
Expand Down Expand Up @@ -172,13 +173,15 @@ export const requestReview = {
const candidateIdentifier = blockUtils.getBlockValue(body, ActionId.CANDIDATE_IDENTIFIER);
const reviewType = blockUtils.getBlockValue(body, ActionId.REVIEW_TYPE).selected_option.text
.text;
// const pdf = blockUtils.getBlockValue(body, ActionId.PDF_IDENTIFIER);
// log.d(pdf);
const pdf = blockUtils.getBlockValue(body, ActionId.PDF_IDENTIFIER);
console.log(body);
console.log(pdf);
log.d(JSON.stringify(pdf));

// Upload PDF to S3 here.
const pdfBufferTest = await stream2buffer(pdf);
const pdfIdentifier = 'Report_Tech_Trials__Auth___Analysis_bskiff_sourceallies.com.pdf';
const pdf = Buffer.from('test file should be here not this');
await putPdfToS3(pdfIdentifier, pdf);
await putPdfToS3(pdfIdentifier, pdfBufferTest);

const numberOfReviewersValue = numberOfReviewers.value;
const deadlineValue = deadline.selected_option.value;
Expand Down Expand Up @@ -289,3 +292,14 @@ function buildReviewTypeOptions(reviewTypes: string[]): PlainTextOption[] {
function buildOption(deadline: Deadline): PlainTextOption {
return { text: { text: DeadlineLabel.get(deadline) || '', type: 'plain_text' }, value: deadline };
}

async function stream2buffer(stream: Stream): Promise<Buffer> {
return new Promise<Buffer>((resolve, reject) => {
/* eslint-disable @typescript-eslint/no-explicit-any */
const _buf = Array<any>();

stream.on('data', chunk => _buf.push(chunk));
stream.on('end', () => resolve(Buffer.concat(_buf)));
stream.on('error', err => reject(`error converting stream - ${err}`));
});
}

0 comments on commit 5dac1c3

Please sign in to comment.