aboutsummaryrefslogtreecommitdiff
path: root/example/echo.scm
blob: 90d0af5eceb3c0d88eb180f6319f646e13e4b49b (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:poll-updates token
                      (lambda (u)
                        (if (telebot:is-message? u)
                          (begin (print-message u)
                                 (echo-message  u)))))