Introduction To Slack
There are still a lot of people who have big questions about what the Slack tool is and how to use it. It can be said simply that Slack is a “chat room” for all employees in your company. Slack users can message chat, and share documents, images, … to everyone in the group quickly.


The biggest advantage of Slack is that it can be used on many different platforms such as computers, Android, and iOS, so all employees in the company can use and chat with each other no matter what device they use.
Reality
That advantage has attracted many international companies to use Slack and led to a situation where it is difficult to communicate in many different languages.
Have you ever been invited to a chat channel where people speak different languages and you have a hard time keeping up with the conversation?


Here’s Why:
- For that reason, I have researched and developed a Slack bot application to help automatically translate channel messages into a language of choice.
This is a simple Slackbot that supports the following features:
- Invite bot to chat channel (public)
- Remove bot from chat channel (public)
- Add language to language list for translation
- Remove the language from the list of languages to translate
- Show list of languages to translate
- Find the code of languages that support translation
Slackbot monitors messages sent to the channel and automatically translates into selected languages (text messages only)
Built With
This section should list any major frameworks/libraries used to bootstrap my project. Leave any add-ons/plugins for the acknowledgments section. Here are a few stacks.


Getting Started
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple steps.
Prerequisites
This is an example of how to list things you need to use the software and how to install them.
- Docker
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
sudo rm -rf /usr/share/keyrings/docker-archive-keyring.gpg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo usermod -a -G docker $USER
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Create .env File, With Keys For:
- Slack tokens – sign up for Slack, “Add a Bot User” to create your bot, and go to the Basic Information panel to find:
SLACK_BOT_TOKENSLACK_SIGNING_SECRETSLACK_APP_TOKEN
Add The Bot To The Slack Workspace:
- enable Slash Commands (see minute 6 of this tutorial)
- modify
SLACK_BOT_TOKENfrom Your Slack App Dashboard -> Install App -> Bot User OAuth Token


- modify
SLACK_SIGNING_SECRETfrom Your Slack App Dashboard -> Basic information -> App Credentials -> Client Secret


- modify
SLACK_APP_TOKENfrom Your Slack App Dashboard -> Basic information -> App-Level Tokens -> Tokens




Add The Bot To The Slack Workspace:
- Go to your Dashboard -> OAuth & Permissions :
- channels:history
- channels:join
- channels:manage
- channels:read
- chat:write
- chat:write.customize
- chat:write.public
- commands
- emoji:read
- groups:history
- groups:write
- im:history
- im:write
- incoming-webhook
- mpim:history
- mpim:write
- users.profile:read
- users:read






- Go to your Dashboard -> Event Subscriptions -> Subscribe to bot events:
- message.channels
- message.groups
- message.im
- message.mpim


Enable Theses Slash Command
- type
/heybot [language]in a slack public channel to invite bot to channel.




- type
/byebot [language]in a public channel that Bot was invited to remove.




- type
/addlang [language]in a public channel that Bot was invited with 2 digit ISO language code to add language.
Example:
/addlang enfor add English to translate languages list./addlang jafor add Japanese to translate languages list./addlang vifor add Vietnamese to translate languages list.




- type
/byelang [language]in a public channel that Bot was invited with 2 digit ISO language code to remove language.
Example:
/byelang enfor remove English to translate languages list./byelang jafor remove Japanese to translate languages list./byelang vifor remove Vietnamese to translate languages list.




- type
/listlangin a public channel that Bot was invited to show current languages list.




- type
/findlangin a public channel that Bot was invited to show supported language list to translate.




Installation
Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn’t rely on any external dependencies or services.
1. Clone the repo
git clone https://github.com/PhanGiaPhat/slack-bot-translate.git
2. Install NPM packages
npm install
3. Modify your TOKEN KEY in .env
SLACK_BOT_TOKEN={SLACK_BOT_TOKEN}
SLACK_APP_TOKEN={SLACK_APP_TOKEN}
SLACK_SIGNING_SECRET={SLACK_SIGNING_SECRET}
- Run with Docker
Modify your TOKEN KEY at readonly variables in start.sh
readonly SLACK_BOT_TOKEN={SLACK_BOT_TOKEN}
readonly SLACK_APP_TOKEN={SLACK_APP_TOKEN}
readonly SLACK_SIGNING_SECRET={SLACK_SIGNING_SECRET}
Run with start.sh
bash start.sh
Roadmap
- Add a bot to the public channel
- Command to find languages to be support
- Command to show a list of languages that translated to
- Command to add language to be translate
- Command to remove language to be translate
- Automatic translation
- Remove bot from the public channel
- Add a bot to a private channel & direct message (developing)
- Able to detect a variety of messages (developing)
- Send a direct message to a bot (developing)
- Multi-language Support
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.

