GitHub - duong2179/slack-transbot

2 min read Original article ↗

Slack translation bot

ToC

Dependencies

  • Slack client library

    pip3 install slackclient

  • Google translate library

    pip3 install googletrans

Translation map

  • Slack-transbot supports M-N translation map:

    channel_1 --> trans_channel_1

    channel_2 --> { trans_channel_1, trans_channel_2 }

Install new slack bot & Obtain slack bot's token

01

02

03

04

05

06

07

08

09

10

11

Create home channel for slack-transbot

Create a private channel (named home-transbot -- e.g). Let use this channel as home channel for slack-transbot. We will do all settings for slack-transbot in the home channel.

12

Invite slack-transbot (named transbot) to the channel.

13

Find slack-transbot user ID

In the home channel, click "View member list" -> Right-click on transbot -> Copy Link -> The copied link should look like https://...slack.com/team/UXXXXXXXX. The last part (UXXXXXXXX) is BOT_ID of slack-transbot.

14

Start slack-transbot

  • export following params as environment variables.

    BOT_TOKEN: Slack-transbot token (xoxb-xxxxxx..., e.g)

    BOT_ID: Slack-transbot user ID (UXXXXXXXX, e.g)

    BOT_NAME: Slack-transbot name (transbot, e.g)

    HOME_CHANNEL: Home channel for slack-transbot (home-transbot, e.g)

  • Start slack-transbot

    python3 /path/to/transbot.py path/to/transmap

    Where: path/to/transmap points to where to save translation map. If launching from scratch, simply points to a non-existing file.

  • Go to the home channel. If slack-transbot has started well you will see transbot is shown with a green circle under Apps section.

Configure slack-transbot

  • To configure slack-transbot, post command messages in the home channel.

  • @transbot help: Say hello and provide you some help.

  • @transbot list: Show translation map.

  • @transbot add src:dst: Add a pair of channels to translation map.

  • @transbot rm src:dst: Remove a pair of channels from translation map.

15

Test slack-transbot

  • Create two channels named test-src and test-dst. Invite slack-transbot to both channels.

  • In the home channel, post @transbot add test-src:test-dst.

16

  • Now, go to test-src channel and post some Korean messages. Check out translated messages in test-dst channel.

17

18