OVEN TransWitcher – Slack Bot Translate

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.

Logo

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?

Logo

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_TOKEN
    • SLACK_SIGNING_SECRET
    • SLACK_APP_TOKEN

Add The Bot To The Slack Workspace:

  • enable Slash Commands (see minute 6 of this tutorial)
  • modify SLACK_BOT_TOKEN from Your Slack App Dashboard -> Install App -> Bot User OAuth Token
botToken
  • modify SLACK_SIGNING_SECRET from Your Slack App Dashboard -> Basic information -> App Credentials -> Client Secret
singingSecret
  • modify SLACK_APP_TOKEN from Your Slack App Dashboard -> Basic information -> App-Level Tokens -> Tokens
genAuthToken
authToken

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
scope1
scope2
scope3
  • Go to your Dashboard -> Event Subscriptions -> Subscribe to bot events:
    • message.channels
    • message.groups
    • message.im
    • message.mpim
events

Enable Theses Slash Command

  • type /heybot [language] in a slack public channel to invite bot to channel.
heybot
heybotCPL
  • type /byebot [language] in a public channel that Bot was invited to remove.
byebot
byebotCPL
  • type /addlang [language] in a public channel that Bot was invited with 2 digit ISO language code to add language.

Example: /addlang en for add English to translate languages list.
/addlang ja for add Japanese to translate languages list.
/addlang vi for add Vietnamese to translate languages list.

addlang
addlangCPL
  • type /byelang [language] in a public channel that Bot was invited with 2 digit ISO language code to remove language.

Example: /byelang en for remove English to translate languages list.
/byelang ja for remove Japanese to translate languages list.
/byelang vi for remove Vietnamese to translate languages list.

byelang
byelangCPl
  • type /listlang in a public channel that Bot was invited to show current languages list.
listlang
listlangCPL
  • type /findlang in a public channel that Bot was invited to show supported language list to translate.
findlang
findlangCPL

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Project Link: https://github.com/PhanGiaPhat/slack-bot-translate
Phan Gia Phat
viVietnamese