-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.lisp
50 lines (42 loc) · 1.89 KB
/
handlers.lisp
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
(in-package :nexmo)
(defun to-url(cmd) (format nil "~A/app?c=~A" *server-callback* cmd) )
(defun add-handler(fn &optional (id (string (gensym))))
(setf (gethash id *handlers*) fn)
id)
(defun app-event(id)
#'(lambda(url params body)
(hunchentoot:log-message* 'event "url:~A,params:~A,body:~A" url params body)
;; (let((res (jsown:parse body)))
;; (when (equal (jsown:val res "status") "started")
;; (let ((result (call-dtmf :id (jsown:val res "uuid"))))
;; (hunchentoot:log-message* 'EventDTMFResult "play-dtmf conversation:~A" result))
;; )
;; )
;;(add-handler (app-event id) id) ;; reregister the event
))
(defun talk(&key (text "hello") (barge-in t)(repeat 1))
#'(lambda(url params body)
(jsown:new-js ("text" text)
("action" "talk")
("loop" repeat)
("bargeIn" barge-in))))
(defun input(handler &key (timeout 3)
(submit-on-hash :null)
(max-digits :null))
#'(lambda(url params body)
(jsown:new-js ("action" "input")
("timeOut" timeout)
("maxDigits" max-digits)
("submitOnHash" submit-on-hash)
("eventUrl" (list (to-url (add-handler #'(lambda(url params body)(funcall handler url params body)))))))))
(defun ncco( &rest items)
#'(lambda(url params body)
(list* (remove-if #'null (mapcar #'(lambda(f)(funcall f url params body)) items)))))
(defun play-dtmf(text)
#'(lambda(url params body)
(hunchentoot:log-message* 'DTMF "play-dtmf conversation:~A ~S" (hunchentoot:get-parameter "conversation_uuid") params)
(let ((res (call-dtmf :id (hunchentoot:get-parameter "conversation_uuid")
:digits text)))
(hunchentoot:log-message* 'DTMFResult "play-dtmf conversation:~A" res))
nil))
;;;;