Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

Commit 2ad2355

Browse files
committed
first commit
0 parents  commit 2ad2355

15 files changed

+567
-0
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DEEPL_AUTH_KEY=********************

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
package
3+
.DS_Store
4+
.slack/
5+
.env

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022- Kazuhiro Sera (@seratch)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# run-on-slack-deepl
2+
3+
This sample app is a translator app that runs [DeepL's awesome APIs](https://www.deepl.com/en/docs-api) for translating Slack message text into a different language.
4+
5+
## Steps to enable this app
6+
7+
### 0. Enable the next-gen platform in your workspace
8+
9+
To use this sample, you first need to install and configure the Slack CLI. Step-by-step instructions can be found in [Quickstart Guide](https://api.slack.com/future/quickstart). Also, the beta platform needs to be enabled for your paid Slack workspace.
10+
11+
And then, you can use this GitHub repository as the template for your app.
12+
13+
```bash
14+
slack create my-deepl-slack-app -t seratch/run-on-slack-deepl
15+
cd my-deepl-slack-app/
16+
```
17+
18+
### 1. Enable reaction_added trigger
19+
20+
First off, open `triggers/reaction_added.ts` source file and modify it to have a valid list of channel IDs to enable this app. And then, run the following CLI command:
21+
22+
```bash
23+
slack deploy
24+
slack trigger create --trigger-def triggers/reaction_added.ts
25+
```
26+
27+
### 2. Set DeepL API key to the app
28+
29+
Add your DeepL API key to the app env variables:
30+
31+
```bash
32+
slack env add DEEPL_AUTH_KEY <your own key here>
33+
```
34+
35+
### 3. Add the app to the channels
36+
37+
Add the deployed app to the channels you've listed in the step 1.
38+
39+
### 4. Add a reaction to a message in the channel
40+
41+
Add `:jp:` reaction to any message in the channel. If everything is fine, you will see the same content that is translated into Japanese in its thread.
42+
43+
<img width="300" src="https://user-images.githubusercontent.com/19658/192277306-b3a2f431-1b8b-44e0-9b6a-224ca09a4b6e.png">
44+
45+
## LICENSE
46+
47+
The MIT License

assets/icon.png

24.8 KB
Loading

deno.jsonc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"importMap": "import_map.json"
3+
}

functions/lang_selector.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { DefineFunction, Schema } from "deno-slack-sdk/mod.ts";
2+
import { SlackFunctionHandler } from "deno-slack-sdk/types.ts";
3+
import { reactionToLang } from "./languages.ts";
4+
5+
export const def = DefineFunction({
6+
callback_id: "lang_selector",
7+
title: "Language selector",
8+
description: "A funtion to identify the language to translate into",
9+
source_file: "functions/lang_selector.ts",
10+
input_parameters: {
11+
properties: {
12+
reaction: {
13+
type: Schema.types.string,
14+
},
15+
},
16+
required: ["reaction"],
17+
},
18+
output_parameters: {
19+
properties: {
20+
lang: {
21+
type: Schema.types.string,
22+
},
23+
},
24+
required: [],
25+
},
26+
});
27+
28+
const handler: SlackFunctionHandler<typeof def.definition> = async ({
29+
inputs,
30+
}) => {
31+
console.log(`lang_selector function called: ${JSON.stringify(inputs)}`);
32+
const reactionName = inputs.reaction;
33+
let lang = undefined;
34+
if (reactionName.match(/flag-/)) {
35+
// flag-***
36+
const matched = reactionName.match(/(?!flag-\b)\b\w+/);
37+
if (matched != null) {
38+
const country = matched[0];
39+
lang = reactionToLang[country];
40+
}
41+
} else {
42+
// jp, fr, etc.
43+
lang = reactionToLang[reactionName];
44+
}
45+
return await { outputs: { lang } };
46+
};
47+
48+
export default handler;

functions/languages.ts

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
export const langToReaction: Record<string, string> = {
2+
en: ":flag-us:",
3+
ja: ":flag-jp:",
4+
zh: ":flag-cn:",
5+
de: ":flag-de:",
6+
fr: ":flag-fr:",
7+
it: ":flag-it:",
8+
es: ":flag-es:",
9+
nl: ":flag-nl:",
10+
pl: ":flag-pl:",
11+
pt: ":flag-pt:",
12+
ru: ":flag-ru:",
13+
bg: ":flag-bg:",
14+
cs: ":flag-cz:",
15+
da: ":flag-dk:",
16+
el: ":flag-gr:",
17+
et: ":flag-ee:",
18+
fi: ":flag-fi:",
19+
hu: ":flag-hu:",
20+
id: ":flag-id:",
21+
lt: ":flag-lt:",
22+
ro: ":flag-ro:",
23+
sk: ":flag-sk:",
24+
sl: ":flag-si:",
25+
sv: ":flag-se:",
26+
tr: ":flag-tr:",
27+
uk: ":flag-ua:",
28+
};
29+
30+
export const langToName: any = {
31+
en: "English",
32+
ja: "Japanese",
33+
zh: "Chinese",
34+
de: "German",
35+
fr: "French",
36+
it: "Italian",
37+
es: "Spanish",
38+
nl: "Dutch",
39+
pl: "Polish",
40+
pt: "Portuguese",
41+
ru: "Russian",
42+
bg: "Bulgarian",
43+
cs: "Czech",
44+
da: "Danish",
45+
el: "Greek",
46+
et: "Estonian",
47+
fi: "Finnish",
48+
hu: "Hungarian",
49+
id: "Indonesian",
50+
lt: "Lithuanian",
51+
ro: "Romanian",
52+
sk: "Slovak",
53+
sl: "Slovenian",
54+
sv: "Swedish",
55+
tr: "Turkish",
56+
uk: "Ukrainian",
57+
};
58+
59+
export const reactionToLang: Record<string, string> = {
60+
ac: "en",
61+
ag: "en",
62+
ai: "en",
63+
ao: "pt",
64+
ar: "es",
65+
as: "en",
66+
at: "de",
67+
au: "en",
68+
aw: "nl",
69+
bb: "en",
70+
be: "nl",
71+
bf: "fr",
72+
bi: "fr",
73+
bj: "fr",
74+
bl: "fr",
75+
bn: "en",
76+
bo: "es",
77+
bq: "nl",
78+
br: "pt",
79+
bs: "en",
80+
bw: "en",
81+
bz: "en",
82+
ca: "en",
83+
cd: "fr",
84+
cf: "fr",
85+
cg: "fr",
86+
ch: "de",
87+
ci: "fr",
88+
ck: "en",
89+
cl: "es",
90+
cm: "fr",
91+
cn: "zh",
92+
co: "es",
93+
cp: "fr",
94+
cr: "es",
95+
cu: "es",
96+
cv: "pt",
97+
cw: "nl",
98+
cx: "en",
99+
de: "de",
100+
dj: "fr",
101+
dm: "en",
102+
do: "es",
103+
ea: "es",
104+
ec: "es",
105+
es: "es",
106+
fj: "en",
107+
fk: "en",
108+
fm: "en",
109+
fr: "fr",
110+
ga: "fr",
111+
gb: "en",
112+
gd: "en",
113+
gf: "fr",
114+
gg: "en",
115+
gh: "en",
116+
gi: "en",
117+
gm: "en",
118+
gn: "fr",
119+
gp: "fr",
120+
gq: "es",
121+
gs: "en",
122+
gt: "es",
123+
gu: "en",
124+
gw: "pt",
125+
gy: "en",
126+
hn: "es",
127+
ic: "es",
128+
im: "en",
129+
io: "en",
130+
it: "it",
131+
je: "en",
132+
jm: "en",
133+
jp: "ja",
134+
ke: "en",
135+
ki: "en",
136+
kn: "en",
137+
ky: "en",
138+
lc: "en",
139+
li: "de",
140+
lr: "en",
141+
mc: "fr",
142+
ml: "fr",
143+
mp: "en",
144+
mq: "fr",
145+
ms: "en",
146+
mu: "en",
147+
mw: "en",
148+
mx: "es",
149+
mz: "pt",
150+
na: "en",
151+
nc: "fr",
152+
ne: "fr",
153+
nf: "en",
154+
ng: "en",
155+
ni: "es",
156+
nl: "nl",
157+
nz: "en",
158+
pa: "es",
159+
pe: "es",
160+
pf: "fr",
161+
pl: "pl",
162+
pm: "fr",
163+
pn: "en",
164+
pr: "es",
165+
pt: "pt",
166+
pw: "en",
167+
py: "es",
168+
re: "fr",
169+
ru: "ru",
170+
sb: "en",
171+
sc: "en",
172+
sg: "en",
173+
sh: "en",
174+
sl: "en",
175+
sm: "it",
176+
sn: "fr",
177+
sr: "nl",
178+
ss: "en",
179+
st: "pt",
180+
sv: "es",
181+
sx: "nl",
182+
ta: "en",
183+
tc: "en",
184+
td: "fr",
185+
tf: "fr",
186+
tg: "fr",
187+
tt: "en",
188+
ug: "en",
189+
um: "en",
190+
us: "en",
191+
uy: "es",
192+
va: "it",
193+
vc: "en",
194+
ve: "es",
195+
vg: "en",
196+
vi: "en",
197+
wf: "fr",
198+
yt: "fr",
199+
zm: "en",
200+
zw: "en",
201+
bg: "bg",
202+
cz: "cs",
203+
dk: "da",
204+
gr: "el",
205+
ee: "et",
206+
fi: "fi",
207+
hu: "hu",
208+
id: "id",
209+
lt: "lt",
210+
ro: "ro",
211+
sk: "sk",
212+
si: "sl",
213+
se: "sv",
214+
tr: "tr",
215+
ua: "uk",
216+
};

0 commit comments

Comments
 (0)