Skip to content

Commit

Permalink
chore(deps): bump @slack/web-api from 6.12.0 to 7.3.4 (#280)
Browse files Browse the repository at this point in the history
Fixes #279

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
jogold and github-actions authored Aug 19, 2024
1 parent e5b615e commit fe6e7b6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 14 additions & 19 deletions src/slack-textract/detect.lambda.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
/* eslint-disable no-console */
import { DetectDocumentTextCommand, TextractClient } from '@aws-sdk/client-textract';
import { WebClient, WebAPICallResult } from '@slack/web-api';
import { WebClient } from '@slack/web-api';
import got from 'got';

export interface SlackEvent {
channel_id: string;
file_id: string;
}

export interface FilesInfoResult extends WebAPICallResult {
file: {
mimetype: string;
filetype: string;
url_private: string;
shares: {
public: {
[channel: string]: [{
ts: string;
}];
};
};
};
}

const textractClient = new TextractClient({});

export async function handler(event: SlackEvent): Promise<void> {
Expand All @@ -33,14 +18,24 @@ export async function handler(event: SlackEvent): Promise<void> {
// Get file info
const info = await slackClient.files.info({
file: event.file_id,
}) as FilesInfoResult;
});
console.log('File info: %j', info);

if (!info.file.mimetype.startsWith('image')) {
if (!info.file) {
console.log('No file');
return;
}

if (!info.file.mimetype?.startsWith('image')) {
console.log('Not an image');
return;
}

if (!info.file.url_private) {
console.log('No private URL');
return;
}

// Get file
const file = await got(info.file.url_private, {
headers: {
Expand All @@ -62,7 +57,7 @@ export async function handler(event: SlackEvent): Promise<void> {
const postMessage = await slackClient.chat.postMessage({
channel: event.channel_id,
text: data.Blocks.filter((b) => b.BlockType === 'LINE').map((b) => b.Text).join('\n'),
thread_ts: info.file.shares.public[event.channel_id][0].ts,
thread_ts: info.file.shares?.public?.[event.channel_id][0].ts,
});
console.log('Post message: %j', postMessage);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/slack-textract/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'aws-sdk-client-mock-jest';
import { DetectDocumentTextCommand, TextractClient } from '@aws-sdk/client-textract';
import { WebClient } from '@slack/web-api';
import { FilesInfoResponse, WebClient } from '@slack/web-api';
import { mockClient } from 'aws-sdk-client-mock';
import got from 'got';
import { handler, FilesInfoResult } from '../../src/slack-textract/detect.lambda';
import { handler } from '../../src/slack-textract/detect.lambda';

process.env.SLACK_TOKEN = 'token';

Expand All @@ -18,7 +18,7 @@ beforeEach(() => {
});

test('handler', async () => {
const fileInfo: FilesInfoResult = {
const fileInfo: FilesInfoResponse = {
ok: true,
file: {
mimetype: 'image/jpg',
Expand Down
104 changes: 48 additions & 56 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe6e7b6

Please sign in to comment.