Skip to content

Commit

Permalink
Update the app
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Apr 4, 2022
1 parent d8a6e00 commit adfd6bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
27 changes: 27 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
{
"name": "DeepL Document Translator for Slack",
"description": "Slack app for DeepL Document Translation API users",
"repository": "https://github.com/seratch/deepl-document-translator-for-slack",
"keywords": [
"Slack",
"Slack API",
"DeepL Pro",
"DeepL API",
"Heroku"
],
"env": {
"SLACK_APP_TOKEN": {
"description": "Slack App-Level Token (https://api.slack.com/apps)",
"value": "xapp-**"
},
"SLACK_BOT_TOKEN": {
"description": "Slack Bot Token (https://api.slack.com/apps)",
"value": "xoxb-**"
},
"DEEPL_AUTH_KEY": {
"description": "DeepL API Auth Key (https://www.deepl.com/pro-account.html)",
"value": "***"
}
},
"image": "heroku/python"
}
8 changes: 5 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@

import deepl
import requests
from deepl import DocumentHandle
from deepl import DocumentHandle, DocumentStatus
from slack_bolt import App, Say, BoltContext, Ack
from slack_bolt.adapter.socket_mode import SocketModeHandler
from slack_sdk import WebClient
Expand Down Expand Up @@ -210,6 210,7 @@ def handle_reaction_added_events(
"We will post a translated file once the translation is done! :bow:",
)

status: Optional[DocumentStatus] = None
try:
status = translator.translate_document_get_status(handle)
while status.ok and not status.done:
Expand All @@ -228,7 229,7 @@ def handle_reaction_added_events(
)
return

if not status.ok:
if status is None or not status.ok:
say(
thread_ts=thread_ts,
# TODO: improve this message to have the error details (need to enhance the DeepL SDK)
Expand All @@ -246,7 247,8 @@ def handle_reaction_added_events(
channels=[channel],
thread_ts=thread_ts,
initial_comment=f"Hey <@{context.user_id}>, thanks for waiting!"
f"Here is :{reaction_name}: (lang: {lang}) translation of `{original_name}` :white_check_mark:",
f"Here is :{reaction_name}: (lang: {lang}) translation of `{original_name}` :white_check_mark:\n"
f"(Spent: {status.billed_characters} characters)",
)
finally:
output_document.close()
Expand Down
13 changes: 11 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ This app provides two features as below.
When a user adds a reaction to a message with files, this app calls [DeepL's document translation API](https://www.deepl.com/docs-api/translating-documents/).
When the translation is done, this app uploads the result as a new file in the message's thread.

<img width="500" src="https://user-images.githubusercontent.com/19658/161464009-fc530afc-36bb-4eb8-a491-98dbb6389552.png">
<img width="500" src="https://user-images.githubusercontent.com/19658/161482554-fe0828c1-4058-4cab-9b20-0c7af9bbdb6b.png">

### Usage Dashboard

Expand All @@ -40,10 40,12 @@ All you need to do to run this app are DeepL API key and Slack app's tokens. Fol

You will use this token as `DEEPL_AUTH_KEY` env variable later.

Also, if your app allows your end-users to translate PDF files as well, go to [Translation Settings](https://www.deepl.com/pro-account/translationSettings) and enable the "Allow PDF files to be sent to Adobe for all your future translations" option.

Refer to the following resources for more details:

* https://www.deepl.com/en/pro/
* https://www.deepl.com/docs-api/
* https://www.deepl.com/pro/change-plan#developer

### Create your Slack App

Expand Down Expand Up @@ -113,6 115,13 @@ export SLACK_BOT_TOKEN=xoxb-...
python app.py
```

## Deployments

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/seratch/deepl-document-translator-for-slack/tree/main)

> If you encounter "We couldn't deploy your app because the source code violates the Salesforce Acceptable Use and External-Facing Services Policy." error with the above button,
> please fork this repository and use your own URL like `https://heroku.com/deploy?template=https://github.com/{your account}/deepl-document-translator-for-slack/tree/main`.

## Related Projects

If you are looking for more functionalities, take a look at the following projects:
Expand Down

0 comments on commit adfd6bc

Please sign in to comment.