This is a DeepL based language translator for Slack. Yaksel will run as a Slack App so it can handle various translation requests from Slack and post the translated message back. You'll need API key to run the translation on DeepL.
It is meant to run on Firebase infrastructure and it will use both Cloud Functions and Realtime Database:
- Cloud Functions - hosts the bot function so it can respond to Slack events
- Real-time Database - keeps the track of translation history (to avoid duplicate messages) and auto-translate settings
+-------+ +------------------------+ +-----------+
| Slack |--->| Yaksel Bot on Firebase |--->| DeepL API |
+-------+ +------------------------+ +-----------+
- The Yaksel bot will wait for events from Slack
- Once Slack sends an event,
Yaksel.handleEvent
will be called, the message gets interpreted, takes whatever action needed. - When it's requested to translate a message, it takes the text content to DeepL and posts the translated message back to Slack.
This instruction will assume you already have the following installed:
- yarn
- firebase-tools
First install all dependencies using yarn
, then configure the firebase project settings using firebase
$ yarn install
$ firebase init
Copy the sample configuration file so that
$ cd functions/src
$ cp .appConfig.example.ts .appConfig.local.ts
$ vim .appConfig.local.ts
app.realtime_database_url
- get it from your firebase projectslack.apikey
- see the "OAuth & Permissions" settings tab in your Slack Appdeepl.apikey
- goto DeepL's web-page, and get the API key
For the production configuration, you'll need to set the values for these variables using firebase-tools
$ firebase functions:config:set app.realtime_database_url="xxx" slack.apikey="xxx" deepl.apikey="xxx"
To test the application, you can simply call the test
script using yarn.
$ yarn test
functions/src
|- models: Contains abstracted datamodels of Slack events, messages and users.
|- services: Contains the implementations of various services to enable translation
|- index.ts: The entrypoint for the Cloud Functions API call
Make sure you have configuration variables set for production. If you're not sure, you can always examine it by calling firebase functions:config:export
Deploy only takes you to enter the following command
$ yarn deploy
There are two objects stored in the database.
Stores the time-stamp of messages that has been translated already. This is needed because one event in Slack can possibly trigger two events.
It keeps the ID of users (or bots) that has auto-translation enabled. The value indicates the target language for the translation.
+(root)
|-channels
| |-C01XXXXXXXX
| | |-1663482586_086500: true
| |-C02XXXXXXXX
| | |-1663811306_114200: true
|-autotranslate
|-U01XXXXXX: "en"
|-B02XXXXXX: "ja"
The Slack bot settings can be tricky, here's the basic settings in Json app manifest format:
{
"display_information": {
"name": "yaksel",
"description": "Your nifty translator powered by DeepL",
"background_color": "#004492"
},
"features": {
"bot_user": {
"display_name": "yaksel",
"always_online": false
}
},
"oauth_config": {
"scopes": {
"bot": [
"channels:history",
"chat:write",
"chat:write.customize",
"groups:history",
"im:history",
"mpim:history",
"reactions:read",
"users:read",
"app_mentions:read"
]
}
},
"settings": {
"event_subscriptions": {
"request_url": "https://us-central1-yaksel-XXXXX.cloudfunctions.net/translate",
"bot_events": [
"app_mention",
"message.channels",
"reaction_added"
]
},
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}