-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_defaults.clj
51 lines (34 loc) · 1.1 KB
/
no_defaults.clj
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
(ns no-defaults
(:require [tg-clj.core :as tg]
[tg-clj-server.poll :as tg-poll]
[tg-clj-server.simple-router :as router]
[tg-clj-server.middleware.me :as me]
[clojure.tools.logging :as log]))
;; >> Handlers
(defn hello-handler [{u :update :keys [client me]}]
(log/info "Hello handler")
; No `invoke` middleware so we call `invoke` ourselves
(tg/invoke client
{:op :sendMessage
:request {:text (str "Hello, I am " (:username me))
:chat_id (get-in u [:message :chat :id])}}))
;; >> Routes
(def routes
[["/hello" #'hello-handler]])
;; >> App
(def app
(-> router/execute-route
; Put more middleware here
me/middleware
(router/select-route-middleware routes)))
; Put more middleware here
(defn main []
(let [client (tg/make-client {:token "<your token>"})]
(tg-poll/run-server client app)))
(comment
;; Run this to start
(def f (future (main)))
;; Available commands:
;; - /hello - Posts a message after the command is input
;; Run this to stop
(future-cancel f))