aboutsummaryrefslogtreecommitdiff
path: root/example/echo.scm
blob: 2e190a7a16b88a21fe972504fd65d9a1c213a84f (plain)
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
(require-extension telebot
                   (prefix telebot telebot:))

(use data-structures)

(define (resolve-query query tree)
  (fold (lambda (x y) (alist-ref x y))
        tree
        query))

(define token (car (command-line-arguments)))

(define (print-message msg)
  (print (resolve-query '(message from first_name) msg)
         ": "
         (resolve-query '(message text) msg)
         " ("
         (resolve-query '(update_id) msg)
         ")"))

(define (echo-message msg)
  (let ((chat_id    (resolve-query '(message from id) msg))
        (text       (resolve-query '(message text)    msg)))
    (telebot:sendMessage token
                         chat_id: chat_id
                         text:    text)))

(telebot:pollUpdates token
                     (lambda (u)
                       (if (telebot:is-message? u)
                         (begin (print-message u)
                                (echo-message  u)))))