Extract text from images posted to Slack using Amazon Textract. The extracted text is posted in a thread under the image and gets indexed!
Create a new Slack app in your workspace, add the
chat:write
and files:read
bot scopes, install it and save its app id, bot token
and signing secret in a AWS Secrets Manager
secret.
This can be done with the AWS CLI:
aws secretsmanager create-secret --name my-slack-app --secret-string '{"appId":"<id>","signingSecret":"<secret>","botToken":"<token>"}'
Define a SlackTextract
in your Stack
and deploy it:
import { SecretValue, Stack, StackProps } from 'aws-cdk-lib';
import * as cloudstructs from 'cloudstructs';
import { Construct } from 'constructs';
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new cloudstructs.SlackTextract(this, 'SlackTextract', {
signingSecret: SecretValue.secretsManager('my-slack-app', { jsonField: 'signingSecret' }),
appId: SecretValue.secretsManager('my-slack-app', { jsonField: 'appId' }).toString(),
botToken: SecretValue.secretsManager('my-slack-app', { jsonField: 'botToken' }),
});
}
}
Look for the API endoint in your stack outputs and use it to enable event subscriptions
in your Slack app and subscribe to the file_shared
events.
Add your app to a channel, share an image and let the magic happen: