aboutsummaryrefslogtreecommitdiff
path: root/telebot.scm
blob: 6d6792de2dce60819979413e442a4fa9441a4597 (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
(module telebot (get-me get-updates send-message)
  (import chicken scheme)
  (use openssl)
  (use http-client)
  (use medea)

  (define api-base "https://api.telegram.org/bot")

  (define (get-query-url token method)
    (string-append api-base token "/" method))

  (define (get-me token)
    (with-input-from-request (get-query-url token "getMe")
                             #f
                             read-json))

  (define (get-updates token)
    (with-input-from-request (get-query-url token "getUpdates")
                             #f
                             read-json))

  (define (send-message token user message)
    (with-input-from-request (get-query-url token "sendMessage")
                             (list (cons 'chat_id user)
                                   (cons 'text    message))
                             read-json))
)