@@ -36,6 +36,47 @@ function clearState(chatId) {
36
36
} ;
37
37
}
38
38
39
+ const messages = {
40
+ start : "Вітаю! \nЦей Бот допомагає створити службову записку, подання або звернення. Для створення натисніть /createfile" ,
41
+ selectDocumentType : "Будь ласка, виберіть тип документа:" ,
42
+ serviceMemo : "Службова записка" ,
43
+ submission : "Подання" ,
44
+ appeal : "Звернення" ,
45
+ noEntries : "Файлів нема" ,
46
+ errorRetrievingRecords : "Помилка при отриманні файлів" ,
47
+ errorChangingFileType : "Помилка при зміні типу файлу на" ,
48
+ errorCreatingRecord : "Помилка при створенні файлу" ,
49
+ errorRetrievingRecord : "Помилка при отриманні файлу" ,
50
+ errorCheckingId : "Помилка при перевірці id" ,
51
+ errorDeletingRecord : "Помилка при видаленні файлу" ,
52
+ errorChangingReceiver : "Помилка при зміні одержувача на" ,
53
+ errorChangingTitle : "Помилка при зміні назви на" ,
54
+ errorChangingContent : "Помилка при зміні тексту на" ,
55
+ enterIdFileToRetrieve : "Введіть id файлу, який ви хочете отримати:" ,
56
+ enterIdFileToEdit : "Введіть id файлу, який ви хочете змінити:" ,
57
+ enterIdFileToDelete : "Введіть id файлу, який ви хочете видалити:" ,
58
+ enterReceiver : "Введіть одержувача:" ,
59
+ whatDoYouWantToChange : "Що ви хочете змінити?" ,
60
+ fileType : "Тип файлу" ,
61
+ receiver : "Одержувача" ,
62
+ title : "Назву" ,
63
+ content : "Текст" ,
64
+ back : "Повернутись" ,
65
+ selectNewFileType : "Оберіть новий тип файлу:" ,
66
+ enterNewReceiver : "Введіть нового одержувача:" ,
67
+ enterNewTitle : "Введіть нову назву:" ,
68
+ enterNewContent : "Введіть новий текст:" ,
69
+ enterValidId : "Такого файлу не існує\\. Введіть правильний id одного з цих файлів\\:" ,
70
+ fileNo : "Файл №" ,
71
+ wasSuccessfullyDeleted : "було успішно видалено" ,
72
+ enterTitle : "Введіть тему файлу:" ,
73
+ enterContent : "Введіть текст файлу:" ,
74
+ memoCreated : "Файл створено!" ,
75
+ } ;
76
+
77
+ const messagesInOneString = Object . values ( messages ) . join ( "\n" ) ;
78
+ console . log ( messagesInOneString ) ;
79
+
39
80
const startDescription = "Перезапустити бота" ;
40
81
const helpDescription = "Переглянути список команд" ;
41
82
const createfileDescription = "Створити файл" ;
@@ -59,7 +100,7 @@ bot.command("start", async (ctx) => {
59
100
const chatId = ctx . chat . id ;
60
101
clearState ( chatId ) ;
61
102
62
- await ctx . reply ( "Вітаю! \nЦей Бот допомагає створити службову записку. Для створення натисніть /createfile" ) ;
103
+ await ctx . reply ( messages . start ) ;
63
104
} ) ;
64
105
65
106
bot . command ( "help" , async ( ctx ) => {
@@ -78,9 +119,9 @@ bot.command("createfile", async (ctx) => {
78
119
const chatId = ctx . chat . id ;
79
120
clearState ( chatId ) ;
80
121
81
- const keyboard = new InlineKeyboard ( ) . text ( "Службова записка" , "service_memo" ) . text ( "Подання" , "submission" ) . text ( "Звернення" , "appeal" ) ;
122
+ const keyboard = new InlineKeyboard ( ) . text ( messages . serviceMemo , "service_memo" ) . text ( messages . submission , "submission" ) . text ( messages . appeal , "appeal" ) ;
82
123
83
- await ctx . reply ( "Будь ласка, виберіть тип документу:" , { reply_markup : keyboard } ) ;
124
+ await ctx . reply ( messages . selectDocumentType , { reply_markup : keyboard } ) ;
84
125
states [ chatId ] . step = "choose_type" ;
85
126
} ) ;
86
127
@@ -93,7 +134,7 @@ bot.command("listfiles", async (ctx) => {
93
134
const responseData = response . data ;
94
135
95
136
if ( Array . isArray ( responseData ) && responseData . length === 0 ) {
96
- await ctx . reply ( "Записів нема" ) ;
137
+ await ctx . reply ( messages . noEntries ) ;
97
138
} else {
98
139
const formattedData = formatFilesList ( responseData ) ;
99
140
@@ -102,7 +143,7 @@ bot.command("listfiles", async (ctx) => {
102
143
} ) ;
103
144
}
104
145
} catch ( error ) {
105
- await ctx . reply ( "Помилка при отриманні записів" ) ;
146
+ await ctx . reply ( messages . errorRetrievingRecords ) ;
106
147
await ctx . reply ( error ) ;
107
148
}
108
149
} ) ;
@@ -112,126 +153,127 @@ bot.command("getfile", async (ctx) => {
112
153
clearState ( chatId ) ;
113
154
114
155
states [ chatId ] . isGetFile = true ;
115
- await ctx . reply ( "Введіть id файлу який ви хочете отримати:" ) ;
156
+ await ctx . reply ( messages . enterIdFileToRetrieve ) ;
116
157
} ) ;
117
158
118
159
bot . command ( "editfile" , async ( ctx ) => {
119
160
const chatId = ctx . chat . id ;
120
161
clearState ( chatId ) ;
121
162
122
163
states [ chatId ] . isEditFile = true ;
123
- await ctx . reply ( "Введіть id файлу який ви хочете змінити:" ) ;
164
+ await ctx . reply ( messages . enterIdFileToEdit ) ;
124
165
} ) ;
125
166
126
167
bot . command ( "deletefile" , async ( ctx ) => {
127
168
const chatId = ctx . chat . id ;
128
169
clearState ( chatId ) ;
129
170
130
171
states [ chatId ] . isDeleteFile = true ;
131
- await ctx . reply ( "Введіть id файлу який ви хочете видалити:" ) ;
172
+ await ctx . reply ( messages . enterIdFileToDelete ) ;
132
173
} ) ;
133
174
134
175
bot . callbackQuery ( "service_memo" , async ( ctx ) => {
135
176
const chatId = ctx . chat . id ;
136
177
137
- states [ chatId ] . type = "СЛУЖБОВА ЗАПИСКА" ;
178
+ states [ chatId ] . type = messages . serviceMemo . toUpperCase ( ) ;
138
179
states [ chatId ] . step = "receiver" ;
139
- await ctx . reply ( "Введіть одержувача:" ) ;
180
+ await ctx . reply ( messages . enterReceiver ) ;
140
181
} ) ;
141
182
142
183
bot . callbackQuery ( "submission" , async ( ctx ) => {
143
184
const chatId = ctx . chat . id ;
144
185
145
- states [ chatId ] . type = "ПОДАННЯ" ;
186
+ states [ chatId ] . type = messages . submission . toUpperCase ( ) ;
146
187
states [ chatId ] . step = "receiver" ;
147
- await ctx . reply ( "Введіть одержувача:" ) ;
188
+ await ctx . reply ( messages . enterReceiver ) ;
148
189
} ) ;
149
190
150
191
bot . callbackQuery ( "appeal" , async ( ctx ) => {
151
192
const chatId = ctx . chat . id ;
152
193
153
- states [ chatId ] . type = "ЗВЕРНЕННЯ" ;
194
+ states [ chatId ] . type = messages . appeal . toUpperCase ( ) ;
154
195
states [ chatId ] . step = "receiver" ;
155
- await ctx . reply ( "Введіть одержувача:" ) ;
196
+ await ctx . reply ( messages . enterReceiver ) ;
156
197
} ) ;
157
198
158
199
bot . callbackQuery ( "back" , async ( ctx ) => {
159
- const keyboard = new InlineKeyboard ( ) . text ( "Тип файлу" , "type" ) . text ( "Одержувача" , "receiver" ) . text ( "Назву" , "title" ) . text ( "Текст" , "content" ) ;
160
- await ctx . reply ( "Що ви хочете змінити?" , { reply_markup : keyboard } ) ;
200
+ const keyboard = new InlineKeyboard ( )
201
+ . text ( messages . fileType , "type" )
202
+ . text ( messages . receiver , "receiver" )
203
+ . text ( messages . title , "title" )
204
+ . text ( messages . content , "content" ) ;
205
+ await ctx . reply ( messages . whatDoYouWantToChange , { reply_markup : keyboard } ) ;
161
206
} ) ;
162
207
163
208
bot . callbackQuery ( "type" , async ( ctx ) => {
164
209
const keyboard = new InlineKeyboard ( )
165
- . text ( "Службова записка" , "newServiceMemo" )
166
- . text ( "Подання" , "newSubmission" )
167
- . text ( "Звернення" , "newAppeal" )
168
- . text ( "Повернутись" , "back" ) ;
169
- await ctx . reply ( "Оберіть новий тип документу:" , { reply_markup : keyboard } ) ;
210
+ . text ( messages . serviceMemo , "newServiceMemo" )
211
+ . text ( messages . submission , "newSubmission" )
212
+ . text ( messages . appeal , "newAppeal" )
213
+ . text ( messages . back , "back" ) ;
214
+ await ctx . reply ( messages . selectNewFileType , { reply_markup : keyboard } ) ;
170
215
} ) ;
171
216
172
217
bot . callbackQuery ( "newServiceMemo" , async ( ctx ) => {
173
218
const chatId = ctx . chat . id ;
174
219
175
- const serviceMemoString = "Службова записка" ;
176
220
try {
177
- const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , serviceMemoString ) ;
221
+ const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , messages . serviceMemo ) ;
178
222
179
223
await ctx . reply ( stringToReply ) ;
180
224
await ctx . replyWithDocument ( inputFile ) ;
181
225
} catch ( error ) {
182
- await ctx . reply ( `Помилка при зміні типу файлу на «${ serviceMemoString } »` ) ;
226
+ await ctx . reply ( `${ messages . errorChangingFileType } «${ messages . serviceMemo } »` ) ;
183
227
await ctx . reply ( error ) ;
184
228
}
185
229
} ) ;
186
230
187
231
bot . callbackQuery ( "newSubmission" , async ( ctx ) => {
188
232
const chatId = ctx . chat . id ;
189
233
190
- const submissionString = "Подання" ;
191
234
try {
192
- const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , submissionString ) ;
235
+ const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , messages . submission ) ;
193
236
194
237
await ctx . reply ( stringToReply ) ;
195
238
await ctx . replyWithDocument ( inputFile ) ;
196
239
} catch ( error ) {
197
- await ctx . reply ( `Помилка при зміні типу файлу на «${ submissionString } »` ) ;
240
+ await ctx . reply ( `${ messages . errorChangingFileType } «${ messages . submission } »` ) ;
198
241
await ctx . reply ( error ) ;
199
242
}
200
243
} ) ;
201
244
202
245
bot . callbackQuery ( "newAppeal" , async ( ctx ) => {
203
246
const chatId = ctx . chat . id ;
204
247
205
- const appealString = "Звернення" ;
206
248
try {
207
- const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , appealString ) ;
249
+ const { stringToReply, inputFile } = await changeFileType ( states [ chatId ] . editFileId , messages . appeal ) ;
208
250
209
251
await ctx . reply ( stringToReply ) ;
210
252
await ctx . replyWithDocument ( inputFile ) ;
211
253
} catch ( error ) {
212
- await ctx . reply ( `Помилка при зміні типу файлу на «${ appealString } »` ) ;
254
+ await ctx . reply ( `${ messages . errorChangingFileType } «${ messages . appeal } »` ) ;
213
255
await ctx . reply ( error ) ;
214
256
}
215
257
} ) ;
216
258
217
259
bot . callbackQuery ( "receiver" , async ( ctx ) => {
218
260
const chatId = ctx . chat . id ;
219
261
220
- await ctx . reply ( "Введіть нового одержувача:" ) ;
262
+ await ctx . reply ( messages . enterNewReceiver ) ;
221
263
states [ chatId ] . step = "newReceiver" ;
222
264
} ) ;
223
265
224
266
bot . callbackQuery ( "title" , async ( ctx ) => {
225
267
const chatId = ctx . chat . id ;
226
268
227
- await ctx . reply ( "Введіть нову назву:" ) ;
269
+ await ctx . reply ( messages . enterNewTitle ) ;
228
270
states [ chatId ] . step = "newTitle" ;
229
271
} ) ;
230
272
231
273
bot . callbackQuery ( "content" , async ( ctx ) => {
232
274
const chatId = ctx . chat . id ;
233
275
234
- await ctx . reply ( "Введіть новий текст:" ) ;
276
+ await ctx . reply ( messages . enterNewContent ) ;
235
277
states [ chatId ] . step = "newContent" ;
236
278
} ) ;
237
279
@@ -250,7 +292,7 @@ bot.on("message:text", async (ctx) => {
250
292
251
293
await ctx . replyWithDocument ( new InputFile ( Buffer . from ( response . data ) , filename ) ) ;
252
294
} catch ( error ) {
253
- await ctx . reply ( "Помилка при створенні запису" ) ;
295
+ await ctx . reply ( messages . errorCreatingRecord ) ;
254
296
await ctx . reply ( error ) ;
255
297
}
256
298
}
@@ -266,7 +308,7 @@ bot.on("message:text", async (ctx) => {
266
308
267
309
await ctx . replyWithDocument ( new InputFile ( Buffer . from ( response . data ) , filename ) ) ;
268
310
} catch ( error ) {
269
- await ctx . reply ( "Помилка при отриманні запису" ) ;
311
+ await ctx . reply ( messages . errorRetrievingRecord ) ;
270
312
}
271
313
}
272
314
@@ -281,12 +323,12 @@ bot.on("message:text", async (ctx) => {
281
323
const responseData = response . data ;
282
324
283
325
if ( Array . isArray ( responseData ) && responseData . length === 0 ) {
284
- await ctx . reply ( "Записів нема" ) ;
326
+ await ctx . reply ( messages . noEntries ) ;
285
327
} else {
286
328
if ( ! responseData . some ( ( item ) => item . id == text ) ) {
287
329
const formattedData = formatFilesList ( responseData ) ;
288
330
289
- await ctx . reply ( `Такого файлу не існує\\. Введіть правильний id одного з цих файлів\\: \n${ formattedData } ` , {
331
+ await ctx . reply ( `${ messages . enterValidId } \n${ formattedData } ` , {
290
332
parse_mode : "MarkdownV2" ,
291
333
} ) ;
292
334
@@ -295,12 +337,16 @@ bot.on("message:text", async (ctx) => {
295
337
}
296
338
}
297
339
} catch ( error ) {
298
- await ctx . reply ( "Помилка при перевірці id" ) ;
340
+ await ctx . reply ( messages . errorCheckingId ) ;
299
341
await ctx . reply ( error ) ;
300
342
}
301
343
302
- const keyboard = new InlineKeyboard ( ) . text ( "Тип файлу" , "type" ) . text ( "Одержувача" , "receiver" ) . text ( "Назву" , "title" ) . text ( "Текст" , "content" ) ;
303
- await ctx . reply ( "Що ви хочете змінити?" , { reply_markup : keyboard } ) ;
344
+ const keyboard = new InlineKeyboard ( )
345
+ . text ( messages . fileType , "type" )
346
+ . text ( messages . receiver , "receiver" )
347
+ . text ( messages . title , "title" )
348
+ . text ( messages . content , "content" ) ;
349
+ await ctx . reply ( messages . whatDoYouWantToChange , { reply_markup : keyboard } ) ;
304
350
}
305
351
306
352
if ( states [ chatId ] . isDeleteFile ) {
@@ -309,9 +355,9 @@ bot.on("message:text", async (ctx) => {
309
355
try {
310
356
await deleteDocumentRequest ( text ) ;
311
357
312
- await ctx . reply ( `Файл № ${ text } було успішно видалено ` ) ;
358
+ await ctx . reply ( `${ messages . fileNo } ${ text } ${ messages . wasSuccessfullyDeleted } ` ) ;
313
359
} catch ( error ) {
314
- await ctx . reply ( "Помилка при видаленні запису" ) ;
360
+ await ctx . reply ( messages . errorDeletingRecord ) ;
315
361
}
316
362
}
317
363
@@ -321,17 +367,17 @@ bot.on("message:text", async (ctx) => {
321
367
case "receiver" :
322
368
states [ chatId ] . receiver = text ;
323
369
states [ chatId ] . step = "title" ;
324
- await ctx . reply ( "Введіть тему записки:" ) ;
370
+ await ctx . reply ( messages . enterTitle ) ;
325
371
break ;
326
372
case "title" :
327
373
states [ chatId ] . title = text ;
328
374
states [ chatId ] . step = "content" ;
329
- await ctx . reply ( "Введіть текст записки:" ) ;
375
+ await ctx . reply ( messages . enterContent ) ;
330
376
break ;
331
377
case "content" :
332
378
states [ chatId ] . content = text ;
333
379
await createDocument ( chatId , ctx ) ;
334
- await ctx . reply ( "Записка створена!" ) ;
380
+ await ctx . reply ( messages . memoCreated ) ;
335
381
clearState ( chatId ) ;
336
382
break ;
337
383
case "newReceiver" :
@@ -342,7 +388,7 @@ bot.on("message:text", async (ctx) => {
342
388
await ctx . reply ( stringToReply ) ;
343
389
await ctx . replyWithDocument ( inputFile ) ;
344
390
} catch ( error ) {
345
- await ctx . reply ( `Помилка при зміні одержувача на «${ text } »` ) ;
391
+ await ctx . reply ( `${ messages . errorChangingReceiver } «${ text } »` ) ;
346
392
await ctx . reply ( error ) ;
347
393
}
348
394
@@ -355,7 +401,7 @@ bot.on("message:text", async (ctx) => {
355
401
await ctx . reply ( stringToReply ) ;
356
402
await ctx . replyWithDocument ( inputFile ) ;
357
403
} catch ( error ) {
358
- await ctx . reply ( `Помилка при зміні назви на «${ text } »` ) ;
404
+ await ctx . reply ( `${ messages . errorChangingTitle } «${ text } »` ) ;
359
405
await ctx . reply ( error ) ;
360
406
}
361
407
@@ -368,7 +414,7 @@ bot.on("message:text", async (ctx) => {
368
414
await ctx . reply ( stringToReply ) ;
369
415
await ctx . replyWithDocument ( inputFile ) ;
370
416
} catch ( error ) {
371
- await ctx . reply ( `Помилка при зміні тексту на «${ text } »` ) ;
417
+ await ctx . reply ( `${ messages . errorChangingContent } «${ text } »` ) ;
372
418
await ctx . reply ( error ) ;
373
419
}
374
420
0 commit comments