forked from web3space/tanos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ls
687 lines (601 loc) · 28 KB
/
index.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
require! {
\require-ls
\./send-media.ls
\./delete-message.ls
\prelude-ls : { obj-to-pairs, join, keys }
\./trace.ls
\express
\body-parser
\cors
\vm
\livescript
\handlebars
\request
\superagent
\./merge-images.ls
\./edit-message.ls
\./make-bot.ls
\./make-db-manager.ls
\greenlock-express : { create }
\greenlock-store-fs
\./create-buttons.ls : { unhash, ishash }
\./telegram-passport.ls : { get-telegram-passport-text, passport-script-proxy, passport-index-proxy, passport-success-proxy, passport-canceled-proxy, proxy-passport-file }
\fs : { read-file, read-file-sync, write-file-sync }
}
validate-attachment = (text, validate-error, cb)->
res = (text ? "").index-of('get-file') > -1
return cb(validate-error ? "Expected Attachment") if res isnt yes
cb null
process-validator = (validator, validate-error, text, cb)->
return cb "text is required" if typeof! text isnt \String
return validate-attachment text, validate-error, cb if validator is \attachment
return cb(validate-error ? "Expected #{validator}") if not text.match(new RegExp(validator))?
cb null
process-validators = ([vaidator, ...rest], validate-error, text, cb)->
return cb null if not validator?
err <- process-validator validator, validate-error, text
return cb err if err?
process-validators rest, validate-error, text, cb
#is-global-menu = (text)->
# text.index-of('') is 0
process-text-validators = (step, { text, type } , cb)->
return cb null if type is \callback_query
#return cb null if is-global-menu text
return cb null if not step.on-text?validate?
{ validate, validate-error } = step.on-text
return process-validators validate, validate-error, text, cb if typeof! validate is \Array
return process-validator validate, validate-error, text, cb if typeof! validate is \String
cb null
module.exports = ({ telegram-token, app,layout, db-type, server-address, server-port, server-ssl-port, bot-name }, cb)->
server-addr =
| server-ssl-port? => "#{server-address.replace(/^http/, 'https')}:#{server-ssl-port}"
| _ => "#{server-address}:#{server-port}"
tanos = {}
bot = make-bot telegram-token
tanos.bot = bot
err, db <- make-db-manager layout, db-type
return cb err if err?
{ get, put, del } = db
tanos.db = db
$app = app tanos
default-user = (chat_id)-> { chat_id }
get-user = (chat_id, cb)->
err, item <- get "#{chat_id}:chat_id"
return cb null, default-user chat_id if err?
return cb null, item if item?
return cb null, default-user chat_id
tanos.get-user = get-user
save-user = (chat_id, user, cb)->
put "#{chat_id}:chat_id", user, cb
tanos.save-user = save-user
save-global = ($global, cb)->
err <- put \variables:global , $global
return cb err if err?
cb null
tanos.save-global = save-global
get-global = (cb)->
err, data <- get \variables:global
obj =
| err? => {}
| _ => data ? {}
cb null, obj
tanos.get-global = get-global
send-each-user = ([chat_id, ...rest], current_step, cb)->
return cb null if not chat_id?
message =
from:
id: chat_id
text: ""
err <- goto current_step, message
return cb err if err?
send-each-user rest, current_step, cb
tanos.send-user = (chat_id, current_step, cb)->
chat_ids =
| typeof! chat_id is \Array => chat_id
| typeof! chat_id is \Number => [chat_id]
send-each-user chat_ids, current_step, cb
get-localized-text = ($user, text)->
return "err: wrong text" if typeof! text isnt \Object
return "err: lang-var is missing" if typeof! text.lang-var isnt \String
lang = eval text.lang-var
return "err: lang is not correct" if typeof! lang isnt \String or lang.length is 0
[ head, ...tail ] = keys text
text[lang] ? text[head] ? "text is not declared"
handler-text-user = (chat_id, input-text, cb)->
err, $user <- get-user chat_id
return cb err if err?
err, $global <- get-global
#console.log \$global.admins, $global.admins
return cb err if err?
text =
| typeof! input-text is \Array => input-text |> join \\n
| typeof! input-text is \String => input-text
| typeof! input-text is \Object => get-localized-text $user, input-text
| _ => "err: unsupported type of text"
template = handlebars.compile text
result = template { $user, $app, $global }
err <- save-global $global
return cb err if err?
cb null, result
run-commands = (message, text, [command, ...commands], cb)->
return cb null if not command?
err <- run-command message, text, command
return cb err if err?
err <- run-commands message, text, commands
return cb err if err?
cb null
save-store-items = ([item, ...items], cb)->
return cb null if not item?
[name, value] = item
err <- put name, value
return cb err if err?
save-store-items items, cb
save-store = ($store, cb)->
pairs =
obj-to-pairs $store
save-store-items pairs, cb
get-chat-id = (message)->
chat_id = (message.chat ? message.from).id
get-user-by-message = (message, cb)->
chat_id = get-chat-id message
err, $user <- get-user chat_id
return cb err if err?
cb null, $user
run-javascript = (message, $text, javascript, cb)->
chat_id = get-chat-id message
err, $user <- get-user-by-message message
return cb err if err?
$chat = message.chat
$message_id = message.message_id
script = new vm.Script javascript
$store = {}
err, $global <- get-global
return cb err if err?
context = new vm.create-context { $user, $app, $store, $text, $chat, $global }
try
script.run-in-context context
catch err
cb err
err <- save-global $global
return cb err if err?
err <- save-user chat_id, $user
return cb err if err?
err <- save-store $store
return cb err if err
cb null
run-function = (message, $text, command, cb)->
chat_id = get-chat-id message
err, $user <- get-user-by-message message
return cb err if err?
$chat = message.chat
$store = {}
err, $global <- get-global
return cb err if err?
javascript = livescript.compile command, { bare: yes }
func = eval "t = #{javascript}"
err <- func { $user, $app, $store, $text, $chat, $global }
return cb err if err?
err <- save-global $global
return cb err if err?
err <- save-user chat_id, $user
return cb err if err?
err <- save-store $store
return cb err if err
cb null
run-livescript = (message, $text, command, cb)->
return run-function message, $text, command, cb if command.index-of(')->') > -1
javascript = livescript.compile command, { bare: yes }
run-javascript message, $text, javascript, cb
run-command = (message, $text, command, cb)->
trace "run command: #{command}"
run-livescript message, $text, command, cb
get-request-resource = (type, resource)-> ({ chat_id, menu-map, name }, cb)->
return cb null if not menu-map[type]?
return cb null, resource if typeof! menu-map[type].lang-var isnt \String and (menu-map[type][name] ? "").to-string!.index-of(resource) is 0
return cb null if typeof! menu-map[type].lang-var isnt \String
err, $user <- get-user chat_id
return cb err if err?
lang = eval menu-map[type].lang-var
return cb null, resource if (menu-map[type][lang]?[name] ? "").to-string!.index-of(resource) is 0
cb null
get-request-location = get-request-resource \menu, \request_location
get-request-contact = get-request-resource \menu, \request_contact
get-request-passport = get-request-resource \buttons, \request_passport
build-command-hash = ({chat_id, current_step, previous_step, name, menu-map}, cb)->
err, data <- get-request-location { chat_id, menu-map, name }
return cb null, data if not err? and data?
err, data <- get-request-contact { chat_id, menu-map, name }
return cb null, data if not err? and data?
err, data <- get-request-passport { chat_id, menu-map, name }
return cb null, data if not err? and data?
#return cb null, "goto:#{previous_step}" if menu-map.buttons?[name] is \goto:$previous-step
#return cb null, "goto:#{previous_step}" if menu-map.menu?[name] is \goto:$previous-step
cb null, "#{current_step}:#{name}"
generate-commands = ({ chat_id, current_step, previous_step, menu-map } , [button, ...buttons], cb)->
return cb null, [] if not button?
[name] = button
err, result <- build-command-hash { chat_id, current_step, previous_step, name, menu-map }
return cb err if err?
err, text <- handler-text-user chat_id, name
return cb err if err?
item = [text, result, button.1]
err, rest <- generate-commands { chat_id, current_step, previous_step, menu-map }, buttons
return cb err if err?
all = [item] ++ rest
cb null, all
on-start = (message, cb)->
on-command { text: '/start' , from: message.chat, type: "message" }, cb
get-images = (menu-map, cb)->
result =
| typeof! menu-map.images is \Array and menu-map.images.length > 0 => menu-map.images
| typeof! menu-map.images is \String => [menu-map.images]
| _ => []
return merge-images menu-map, cb if result.length is 0
cb null, result
get-localized-buttons = ({ chat_id, buttons }, cb)->
return cb null, buttons if typeof! buttons.lang-var isnt \String
err, $user <- get-user chat_id
lang = eval buttons.lang-var
result = buttons[lang] ? {}
cb null, result
get-buttons-generic = (name)-> ({chat_id, current_step, menu-map, previous_step }, cb)->
buttons = menu-map[name] ? {}
err, buttons <- get-localized-buttons { chat_id, buttons }
return cb err if err?
pairs =
buttons |> obj-to-pairs
err, commands <- generate-commands { chat_id, current_step, previous_step, menu-map }, pairs
return cb err if err?
cb null, commands
get-menu = get-buttons-generic \menu
get-buttons = get-buttons-generic \buttons
get-previous-step-key = (message)->
"#{message.from.id}:previous-step"
goto-all = ([current_step, ...steps], message, cb)->
return cb null, yes if not current_step?
err, success <- goto current_step, message
return cb err, success if err?
goto-all steps, message, cb
delete-message-if-exists = ({ chat_id, message_id }, cb)->
return cb null if not message_id?
delete-message { bot, chat_id, message_id}, cb
process-condition = (command, message, cb)->
javascript = livescript.compile command, { bare: yes }
err, $user <- get-user-by-message message
return cb err if err?
err, $global <- get-global
return cb err if err?
script = new vm.Script javascript
$check =
result: no
context = new vm.create-context { $user, $app, $check, $global }
try
script.run-in-context context
catch err
return cb err
cb null, $check.result
process-conditions = ([condition, ...conditions], message, cb)->
return cb null if not condition?
err, data <- process-condition condition.0, message
return cb err if err?
return cb null, condition.1 if data is yes
process-conditions conditions, message, cb
check-show-next = (current-step, message, cb)->
return cb null if typeof! current-step?goto isnt \String
cb null, current-step?goto
check-regirect-conditions = (current-step, message, cb)->
return cb null if not current-step?redirect-condition?
return cb "redirect condition should be an object" if typeof! current-step?redirect-condition isnt \Object
redirect-conditions =
current-step?redirect-condition |> obj-to-pairs
process-conditions redirect-conditions, message, cb
#unvar-step = (current_step_guess, message, cb)->
# return cb null, current_step_guess if current_step_guess.index-of('{{') is -1
# err, current_step <- handler-text-user message.from.id, current_step_guess
# return cb err if err?
# cb null, current_step
execute-on-enter = (menu-map, message, cb)->
on-enter =
| typeof! menu-map.on-enter is \Array => menu-map.on-enter
| typeof! menu-map.on-enter is \String => [menu-map.on-enter]
| _ => []
text = \#enter
err <- run-commands message, text, on-enter
return cb err if err?
cb null
state =
menu: null
goto = (current_step, message, cb)->
console.log \goto, current_step
#err, current_step <- unvar-step current_step_guess, message
return cb err, no if err?
err, previous_step <- get-previous-step message
return cb err, no if err?
previous-step-key = get-previous-step-key message
err, retrieved <- retrieve-last-step-for-user message, current_step, previous_step
return cb err, no if err?
name-menu = "#{current_step}:bot-step"
err <- put previous-step-key, current_step
return cb err, no if err?
err, current-map <- get "#{current_step}:bot-step"
err, regirect_step <- check-regirect-conditions current-map, message
return cb err, no if err?
return goto regirect_step, message, cb if regirect_step?
return cb err, no if err?
err, main-map <- get "main:bot-step"
return cb err, no if err?
menu-map = current-map ? main-map
err <- execute-on-enter menu-map, message
return cb err, no if err?
chat_id = message.from.id
err, menu-guess <- get-menu { chat_id, current_step, menu-map, previous_step }
return cb err, no if err?
err, buttons <- get-buttons { chat_id, current_step, menu-map, previous_step }
return cb err, no if err?
err, images <- get-images menu-map
return cb err, no if err?
photo =
| typeof! images is \Undefined => null
| typeof! images is \Array => images.0
| typeof! images is \String => images
| _ => null
chat = message.from
err, text <- handler-text-user chat_id, menu-map.text
return cb err, no if err?
menu =
| keys(buttons).length > 0 => null
| _ => menu-guess
state.menu = menu ? state.menu
message-body = { bot, chat, photo, buttons, text, menu, server-addr }
err, next-message <- send-media message-body
return cb err, no if err?
err <- put "#{next-message.message_id}:message", { current_step, ...message-body }
return cb err, no if err?
err, message_id <- get "${chat_id}.#{current_step}"
<- delete-message-if-exists { chat_id, message_id }
err <- put "${chat_id}.#{current_step}", next-message.message_id
return cb err, no if err?
err, show_next <- check-show-next current-map, message
return goto show_next, message, cb if show_next?
return cb err, no if err?
console.log \YES
cb null, yes
retrieve-last-step-for-user = (message, current_step, previous_step, cb)->
err, $user <- get-user-by-message message
return cb err if err?
$user.currentStep = $user.currentStep ? current_step
if current_step?
if current_step isnt \main-step-help and previous_step isnt \main-step-help
if current_step is \main-step-help
$user.currentStep = previous_step
if previous_step is \main-step-help
$user.currentStep = current_step
else if current_step isnt \main-step-help and previous_step is \main-step-help
$user.currentStep = current_step
else if current_step is \main-step-help and previous_step isnt \main-step-help
$user.currentStep = previous_step
err <- save-user $user.chat_id, $user
return cb err if err?
cb null, yes
get-previous-step = (message, cb)->
previous-step-key = get-previous-step-key message
err, previous_step_guess <- get previous-step-key
err, previous-message-body <- get "#{message?message?message_id}:message"
text = message.data ? ""
previous_step =
| text.index-of(\:) > -1 and text.index-of(\goto:) is -1 => text.split(\:).0
| previous-message-body? => previous-message-body.current_step
| previous_step_guess? => previous_step_guess
| _ => \main
cb null, previous_step
prevent-action = ({ bot, chat, text}, cb)->
err <- send-media { bot, chat, text, server-addr }
return cb err, no if err?
return cb null, yes
get-text = (message, cb)->
return get-telegram-passport-text {server-addr, db }, message, cb if message.passport_data?
get-last = (message)->
length = message.photo.length
message.photo[length - 1]
text =
| message.data? => message.data
| message.text? => message.text
| message.contact? => "#{message.contact.phone_number} #{message.contact.first_name} #{message.contact.last_name}"
| message.location? => "<a href='https://www.google.com/maps/@#{message.location.latitude},#{message.location.longitude},15z'>Место на карте</a>"
| message.document? => "<a href='#{server-addr}/get-file/#{message.document.file_id}'>Документ</a>"
| message.photo? => "<a href='#{server-addr}/get-file/#{get-last(message).file_id}'>Фотография</a>"
| message.video? => "<a href='#{server-addr}/get-file/#{message.video.file_id}'>Видео</a>"
| message.voice? => "<a href='#{server-addr}/get-file/#{message.voice.file_id}'>Запись голоса</a>"
| _ => message.text
return cb null, text
no-buttons = (step)-> not step.buttons? and not step.menu?
extract-localized-buttons = ({ message, buttons }, cb)->
return cb "message is required" if not message?
return cb "buttons object is required" if typeof! buttons isnt \Object
return cb null, buttons if typeof! buttons.lang-var isnt \String
err, $user <- get-user-by-message message
return cb err if err?
lang = eval buttons.lang-var
cb null, buttons[lang]
extract-by-button = ({ message, text }, type, input-buttons, cb)->
buttons =
| type isnt \menu => input-buttons
| _ => state.menu
return cb "buttons not found" if not buttons?
err, buttons <- extract-localized-buttons { message, buttons }
return cb err if err?
return cb "buttons not found" if not buttons?
name =
| (text ? "").index-of(':') > -1 => text.split(':').1
| _ => text
res = buttons[name] ? buttons[text]
cb null, res
extract-button = ({ text, previous-step, main-step, message }, cb)->
#console.log \extract-button, text
return cb "previous-step is required" if not previous-step?
button =
| not text? => \goto:main
| (text ? "").index-of('goto:') > -1 => text
| previous-step.on-text? and message.type isnt \callback_query => previous-step.on-text
| no-buttons(previous-step) => null
return cb null, button if button?
err, button <- extract-by-button { message, text }, \buttons , previous-step.buttons
return cb null, button if button?
# button not found in current step, so will try to find in main step
err, button <- extract-by-button { message, text }, \menu , previous-step.menu
return cb null, button if button?
err, button <- extract-by-button { message, text }, \buttons, main-step.buttons
return cb null, button if button?
err, button <- extract-by-button { message, text }, \menu , main-step.menu
return cb null, button if button?
cb null, null
on-command = (message, cb)->
#console.log \on-command, { message.type, message.data, message.text }
return cb null, no if not message?message?message_id?
err, previous_step <- get-previous-step message
return cb err, no if err?
err, text <- get-text message
return cb err if err?
err, main-step <- get "main:bot-step"
return cb err if err?
err, previous-step-guess <- get "#{previous_step}:bot-step"
previous-step = previous-step-guess ? main-step
err <- process-text-validators previous-step, { text, message.type }
return prevent-action { bot, chat: message.from, text: "#{err}" }, cb if err?
err, clicked-button <- extract-button { text, previous-step, main-step, message }
#console.log clicked-button
#return cb err if err?
button-not-found = message.text? and not message.data? and clicked-button is null and previous_step isnt \main
#console.log \!!!BUTTON-NOT-FOUND, message.text if button-not-found
#return on-command {data: "main:#{message.text}", ...message }, cb if button-not-found
return cb null, yes if button-not-found
clicked-button = clicked-button ? \goto:main
commands =
| typeof! clicked-button.store is \String => [clicked-button.store]
| typeof! clicked-button.store is \Array => clicked-button.store
| _ => []
err <- run-commands message, text, commands
return cb err, no if err?
current_step =
| typeof! clicked-button is \String => clicked-button.split(':').1
| typeof! clicked-button is \Object => clicked-button.goto
| _ => null
return cb null, yes if not current_step?
current-steps = current_step.split(',')
#return cb null, yes if current-steps.length is 0
#console.log { current-steps }
err, success <- goto-all current-steps, message
cb err, success
handlers = { on-command, on-start }
handler-keys = Object.keys handlers
store-username = (message, cb)->
return cb null if not message.chat?
err <- put "#{message.chat.username}:username", message.chat.id
return cb err if err?
err <- put "#{message.chat.id}:chat_id->username", message.chat.username
return cb err if err?
cb null
process-handlers = ([handler, ...rest], message, cb)->
return cb null, no if not handler?
chat_id = message.from.id
err <- store-username message
return cb err if err?
{ message_id } = message.message
err, result <- handlers[handler] message
return cb err, no if err?
return cb null, yes if result
err, result <- process-handlers rest, message
cb err, result
process-messsage = (query, cb)->
{ message } = query
return cb null if not message?
result <- process-handlers handler-keys, query
cb null, result
update-previous-messsage = ({ type, message }, cb)->
return cb null if type is \message
return cb null if not message?message?
option =
| message.data?index-of(':') > -1 => message.data.split(":").1
| _ => message.data
err, message-body <- get "#{message.message.message_id}:message"
return cb err if err?
chat_id = message.message.chat.id
message_id = message.message.message_id
text = "#{message-body.text}\n\n`#{option}`"
err <- edit-message bot, server-addr, chat_id, message_id, text, {}, {}
cb null
bot.on \update , (result)->
message = result.message ? result.callback_query
#message.text = unhash message.text if message.text?
message.data = unhash message.data if message.data?
type =
| result.callback_query? => \callback_query
| message.text? and message.text.index-of('') > -1 => \callback_query
| _ => \message
message.text = message.text.replace('', '') if message.text?
<- update-previous-messsage { type, message }
process-messsage { message, type, ...message }, trace
get-from-id = ({ message, token }, cb)->
err, record <- get "#{token}:access-keys"
return cb err if err?
return cb "not found registered record for token" if typeof! record isnt \Object
{ chat_id, steps } = record
return cb "step is not permitted" if steps.index-of(message) > -1
err, user <- get "#{chat_id}:chat_id"
return cb err if err?
err <- del "#{token}:access-keys"
return cb err if err?
cb null, user
process-http-message = (body, cb)->
{ message, token } = req.body
return cb "message is required" if not message?
return cb "token is required" if not token?
err, id <- get-from-id { message, token }
return cb err if err?
from = { id }
err, result <- process-messsage { message, from }
return cb err if err?
cb null, result
restify = (res)-> (err, result)->
return res.status(400).send "#{err.message ? err}" if err?
res.send result
proxy-file = (req, res)->
{ file_id } = req.params
err, data <- bot.get-file { file_id }
return res.status(400).send("cannot get file: #{err}") if err?
request.get("https://api.telegram.org/file/bot#{telegram-token}/#{data.file_path}").pipe(res)
tanos.http = express!
start-with-ssl = (cb)->
greenlock =
create do
email: \[email protected]
agreeTos: yes
config-dir: \./config/acme/
community-member: no
telemetry: no
app: tanos.http
debug: no
store: greenlock-store-fs
greenlock.listen(server-port, server-ssl-port)
cb err, tanos
start-without-ssl = (cb)->
err <- tanos.http.listen server-port
cb err, tanos
tanos.http
.use body-parser.urlencoded({ extended: true })
.use body-parser.json!
.use cors!
.get \/telegram-passport/script.js , passport-script-proxy
.get \/telegram-passport/index.html , passport-index-proxy { server-addr, telegram-token, db, bot-name }
.get \/telegram-passport/tg_passport=success , passport-success-proxy({ bot-name })
.get \/telegram-passport/tg_passport=canceled , passport-canceled-proxy({ bot-name })
.get \/telegram-passport , passport-success-proxy({ bot-name })
.get \/get-file/:file_id, proxy-file
.get \/get-decrypted-file/:file_id, proxy-passport-file { bot, telegram-token, db }
#.get \/google8b809baeb12ee9e4.html, (req, res)-> res.sendFile(__dirname+"/google8b809baeb12ee9e4.html") # for excel
.post \/api/message/:message/:token , (req, res) -> process-http-message req.params, restify(res)
.get \/api/message/:message/:token , (req, res)-> process-http-message req.params, restify(res)
start =
| server-ssl-port? => start-with-ssl
| _ => start-without-ssl
start cb