1
1
import crypto from "crypto" ;
2
+ import { t } from "i18next" ;
2
3
import Router from "koa-router" ;
3
4
import { escapeRegExp } from "lodash" ;
4
5
import { IntegrationService } from "@shared/types" ;
@@ -18,6 +19,7 @@ import {
18
19
import SearchHelper from "@server/models/helpers/SearchHelper" ;
19
20
import { presentSlackAttachment } from "@server/presenters" ;
20
21
import { APIContext } from "@server/types" ;
22
+ import { opts } from "@server/utils/i18n" ;
21
23
import * as Slack from "@server/utils/slack" ;
22
24
import { assertPresent } from "@server/validation" ;
23
25
@@ -150,21 +152,6 @@ router.post("hooks.slack", async (ctx: APIContext) => {
150
152
assertPresent ( user_id , "user_id is required" ) ;
151
153
verifySlackToken ( token ) ;
152
154
153
- // Handle "help" command or no input
154
- if ( text . trim ( ) === "help" || ! text . trim ( ) ) {
155
- ctx . body = {
156
- response_type : "ephemeral" ,
157
- text : "How to use /outline" ,
158
- attachments : [
159
- {
160
- text :
161
- "To search your knowledge base use `/outline keyword`. \nYou’ve already learned how to get help with `/outline help`." ,
162
- } ,
163
- ] ,
164
- } ;
165
- return ;
166
- }
167
-
168
155
let user , team ;
169
156
// attempt to find the corresponding team for this request based on the team_id
170
157
team = await Team . findOne ( {
@@ -225,12 +212,39 @@ router.post("hooks.slack", async (ctx: APIContext) => {
225
212
}
226
213
}
227
214
215
+ // Handle "help" command or no input
216
+ if ( text . trim ( ) === "help" || ! text . trim ( ) ) {
217
+ ctx . body = {
218
+ response_type : "ephemeral" ,
219
+ text : "How to use /outline" ,
220
+ attachments : [
221
+ {
222
+ text : t (
223
+ "To search your knowledgebase use {{ command }}. \nYou’ve already learned how to get help with {{ command2 }}." ,
224
+ {
225
+ command : `/outline keyword` ,
226
+ command2 : `/outline help` ,
227
+ ...opts ( user ) ,
228
+ }
229
+ ) ,
230
+ } ,
231
+ ] ,
232
+ } ;
233
+ return ;
234
+ }
235
+
228
236
// This should be super rare, how does someone end up being able to make a valid
229
237
// request from Slack that connects to no teams in Outline.
230
238
if ( ! team ) {
231
239
ctx . body = {
232
240
response_type : "ephemeral" ,
233
- text : `Sorry, we couldn’t find an integration for your team. Head to your ${ env . APP_NAME } settings to set one up.` ,
241
+ text : t (
242
+ `Sorry, we couldn’t find an integration for your team. Head to your {{ appName }} settings to set one up.` ,
243
+ {
244
+ ...opts ( user ) ,
245
+ appName : env . APP_NAME ,
246
+ }
247
+ ) ,
234
248
} ;
235
249
return ;
236
250
}
@@ -292,7 +306,13 @@ router.post("hooks.slack", async (ctx: APIContext) => {
292
306
query : text ,
293
307
results : totalCount ,
294
308
} ) ;
295
- const haventSignedIn = `(It looks like you haven’t signed in to ${ env . APP_NAME } yet, so results may be limited)` ;
309
+ const haventSignedIn = t (
310
+ `It looks like you haven’t signed in to {{ appName }} yet, so results may be limited` ,
311
+ {
312
+ ...opts ( user ) ,
313
+ appName : env . APP_NAME ,
314
+ }
315
+ ) ;
296
316
297
317
// Map search results to the format expected by the Slack API
298
318
if ( results . length ) {
@@ -312,7 +332,7 @@ router.post("hooks.slack", async (ctx: APIContext) => {
312
332
? [
313
333
{
314
334
name : "post" ,
315
- text : "Post to Channel" ,
335
+ text : t ( "Post to Channel" , opts ( user ) ) ,
316
336
type : "button" ,
317
337
value : result . document . id ,
318
338
} ,
@@ -324,15 +344,24 @@ router.post("hooks.slack", async (ctx: APIContext) => {
324
344
325
345
ctx . body = {
326
346
text : user
327
- ? `This is what we found for "${ text } "…`
328
- : `This is what we found for "${ text } " ${ haventSignedIn } …` ,
347
+ ? t ( `This is what we found for "{{ term }}"` , {
348
+ ...opts ( user ) ,
349
+ term : text ,
350
+ } )
351
+ : t ( `This is what we found for "{{ term }}"` , {
352
+ term : text ,
353
+ } ) + ` (${ haventSignedIn } )…` ,
329
354
attachments,
330
355
} ;
331
356
} else {
332
357
ctx . body = {
333
358
text : user
334
- ? `No results for "${ text } "`
335
- : `No results for "${ text } " ${ haventSignedIn } ` ,
359
+ ? t ( `No results for "{{ term }}"` , {
360
+ ...opts ( user ) ,
361
+ term : text ,
362
+ } )
363
+ : t ( `No results for "{{ term }}"` , { term : text } ) +
364
+ ` (${ haventSignedIn } )…` ,
336
365
} ;
337
366
}
338
367
} ) ;
0 commit comments