Translate Slack message with flag emoji(e.g. 🇯🇵 🇺🇸 🇬🇧) reaction. 😄 Use only AWS Products(AWS Lambda functions in Go, Amazon Comprehend, Amazon Translate)
This is implemented slack/reacjilator with AWS Products. (AWS Lambda functions in Go, Amazon Comprehend, Amazon Translate)
You can easily translate Slack messages with flag emojiflag emoji(e.g. 🇯🇵 🇺🇸 🇬🇧) reaction.
The translated messages is sent back to the thread, so it does not interfere with other conversations.
- It works easily as Slack bot.
- Use only AWS Products.
- Of course, even when using other translation API you can easily respond.
- Since it is a serverless configuration, it is easy to build and deploy.
-
golang 1.10+
-
Packages in use
- aws/aws-sdk-go: AWS SDK for the Go programming language.
- kelseyhightower/envconfig: Golang library for managing configuration data from environment variables
- nlopes/slack: Slack API in Go
- https://github.com/nlopes/slack
- If the following pull requests are not merged it may not work with "invalid_limit" errors.
- Fixed "invalid_limit" error occurs. by uchimanajet7 · Pull Request #272 · nlopes/slack
- If the following pull requests are not merged it may not work with "invalid_limit" errors.
- https://github.com/nlopes/slack
-
Services in use
- Amazon API Gateway
- AWS Lambda – Serverless Compute - Amazon Web Services
- Amazon Translate – Neural Machine Translation - AWS
- Amazon Comprehend - Natural Language Processing (NLP) and Machine Learning (ML)
- Slack API | Slack
-
Tools in use
- AWS Command Line Interface
- awslabs/serverless-application-model: AWS Serverless Application Model (AWS SAM) prescribes rules for expressing Serverless applications on AWS.
Install this bot on "Slack".
If you react to the message with the emoji of the flag, this bot translate the original message and post it under the message thread.
However, whether it can be translated depends on the product used for translation.
-
Refer to the following document and install this bot in "Slack".
- slackapi/reacjilator: A translation bot that translates a message when a user reacted with an emoji 🇨🇳 🇮🇹 🇹🇭 🇫🇷 🇯🇵 🇮🇳 🇺🇸 🇧🇬 🇹🇼 🇦🇪 🇰🇷
- [Japanese] Developing a bot for your workspace 翻訳ボットを作る!
-
If you build from source yourself.
$ go get github.com/uchimanajet7/go-reacjilator
$ cd $GOPATH/src/github.com/uchimanajet7/go-reacjilator
$ go build
- Build and Deploy bot using
AWS CLI
andAWS SAM
.
For deployment you need to be able to run the AWS CLI and prepare the AWS S3 resources necessary for AWS Lambda's operation in advance.
- Deploying Lambda-based Applications - AWS Lambda
$ GOARCH=amd64 GOOS=linux go build -v -o build/go-reacjilator
$ aws cloudformation package \
--template-file template.yml \
--s3-bucket <YOUR_BUCKET_NAME> \
--s3-prefix go-reacjilator \
--output-template-file .template.yml
$ export SLACK_TOKEN=<YOUR_SLACK_TOKEN>
$ export SLACK_VERIFICATION_TOKEN=<YOUR_ SLACK_VERIFICATION_TOKEN>
$ export SLACK_CHANNEL_ID=<YOUR_SLACK_CHANNEL_ID>
$ aws cloudformation deploy \
--template-file .template.yml \
--stack-name go-reacjilator \
--capabilities CAPABILITY_IAM \
--parameter-overrides "SlackToken=$SLACK_TOKEN" "SlackVerificationToken=$SLACK_VERIFICATION_TOKEN" "SlackChannelID=$SLACK_CHANNEL_ID"
- About setting items
s3-bucket <YOUR_BUCKET_NAME>
: required- Specify the bucket name of AWS S3 prepared in advance.
SLACK_TOKEN=<YOUR_SLACK_TOKEN>
: required- Specify the token to use "Slack API".
SLACK_VERIFICATION_TOKEN=<YOUR_ SLACK_VERIFICATION_TOKEN>
: required- Specify the verification token to use "Slack API".
SLACK_CHANNEL_ID=<YOUR_SLACK_CHANNEL_ID>
: optional- Specify slack channel ID to allow.
- When you want to use channel filter
- If you want to limit the channels that respond to flag emoji reactions, you need to specify one allowed channel.
- Specify the
channel ID
. - Refer to the following for how to check the
channel ID
.- Slack | APIに使う「チャンネルID」を取得する方法 - Qiita
- When you want to use channel filter
- Specify slack channel ID to allow.
- AWS Lambda Go, Amazon Comprehend, Amazon Translate で作るSlack 翻訳Bot #aws #lambda #slack #golang #serverless - uchimanajet7のメモ