The Image Moderator Chatbot serverless reference architecture demonstrates how to leverage Amazon Re...
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
Administrators of large channels in popular chat apps can struggle to protect their users from trolls posting explicit or suggestive images. The Image Moderation Chatbot Serverless reference architecture solves this problem by using Amazon API Gateway, AWS Lambda, and Amazon Rekognition's image moderation deep learning feature to check images contained in messages posted to channels for explicit or suggestive content. Image moderation provides a hierarchical list of labels for each image with confidence scores to enable fine-grained control over what images to allow. Images found to contain explicit or suggestive content labels above a minimum confidence interval are automatically removed by the bot, and a message explaining the removal is posted by the bot to the originating channel.
This repository contains sample code for all the Lambda functions depicted in the diagram below as well as an AWS CloudFormation template for creating the functions and related resources.
To see some of the other powerful features of Amazon Rekognition in action check out the Image Recognition and Processing Backend Serverless reference architecture
Basic Informationtab under
Settingstake note of the
Verification Tokenas it will be required later 1. Navigate to the
OAuth & Permissionstab under
Features1. Under the
Permissions Scopessection add the following permission scopes * channels:history * chat:write:bot * files:read * files:write:user 1. Click
Save Changes1. Click
Install App to Teamthen
Authorizethen note the
OAuth Access Tokenas it will be required later
This bot can be launched into any region that supports the underlying services from the Serverless Application Repository using the instructions below:
Configure application parameters
Deployto deploy the chatbot
If you would like to deploy the template manually, you need a S3 bucket in the target region, and then package the Lambda functions into that S3 bucket by using the
aws cloudformation packageutility.
Set environment variables for later commands to use:
S3BUCKET=[REPLACE_WITH_YOUR_BUCKET] REGION=[REPLACE_WITH_YOUR_REGION] STACKNAME=[REPLACE_WITH_DESIRED_NAME] VTOKEN=[REPLACE_WITH_VERIFICATION_TOKEN] ATOKEN=[REPLACE_WITH_OAUTH_ACCESS_TOKEN]
Then go to the
cloudformationfolder and use the
aws cloudformation packageutility
aws cloudformation package --region $REGION --s3-bucket $S3BUCKET --template image_moderator.serverless.yaml --output-template-file image_moderator.output.yaml
Last, deploy the stack with the resulting yaml (
image_moderator.output.yaml) through the CloudFormation Console or command line:
aws cloudformation deploy --region $REGION --template-file image_moderator.output.yaml --stack-name $STACKNAME --capabilities CAPABILITY_NAMED_IAM --parameter-overrides VerificationToken=$VTOKEN AccessToken=$ATOKEN
RequestURLoutput from the created stack as it will be required later
Event Subscriptionstab under
Featuresand enable events
Request URLfield enter the
RequestURLvalue noted earlier
Add Workspace Eventand select
To test the example open your Slack bot and attempt to upload the sample images from the Amazon Rekognition console demo, which can be downloaded from the links below: - Family Picnic (will not be removed by bot) - Yoga Swimwear (will be removed by bot)
To remove all resources created by this example, do the following:
The following sections explain all of the resources created by the CloudFormation template provided with this example.
This reference architecture sample is licensed under Apache 2.0.