|
@@ -4,22 +4,6 @@
|
|
|
(defparameter +telegram-api-format+ "https://api.telegram.org/bot~A/~A")
|
|
(defparameter +telegram-api-format+ "https://api.telegram.org/bot~A/~A")
|
|
|
(defvar *telegram-timeout* 30 "Default Telegram timeout")
|
|
(defvar *telegram-timeout* 30 "Default Telegram timeout")
|
|
|
|
|
|
|
|
-;; (defun %telegram-api-call (method &optional args)
|
|
|
|
|
-;; (let* ((params (loop for (k . v) in args collect (cons
|
|
|
|
|
-;; (princ-to-string k)
|
|
|
|
|
-;; (princ-to-string v))))
|
|
|
|
|
-;; (response (yason:parse
|
|
|
|
|
-;; (flexi-streams:octets-to-string
|
|
|
|
|
-;; (drakma:http-request (format nil +telegram-api-format+ *telegram-token* method)
|
|
|
|
|
-;; :method :post
|
|
|
|
|
-;; :parameters params
|
|
|
|
|
-;; :external-format-out :utf8)
|
|
|
|
|
-;; :external-format :utf8)
|
|
|
|
|
-;; :object-as :alist)))
|
|
|
|
|
-;; (unless (aget "ok" response)
|
|
|
|
|
-;; (error (aget "description" response)))
|
|
|
|
|
-;; (aget "result" response)))
|
|
|
|
|
-
|
|
|
|
|
(defun %telegram-api-call (method &optional args)
|
|
(defun %telegram-api-call (method &optional args)
|
|
|
(let* ((params (loop for (k . v) in args collect (cons
|
|
(let* ((params (loop for (k . v) in args collect (cons
|
|
|
(princ-to-string k)
|
|
(princ-to-string k)
|
|
@@ -28,17 +12,17 @@
|
|
|
(timeout (+ 5 (or (cdr (assoc :timeout args))
|
|
(timeout (+ 5 (or (cdr (assoc :timeout args))
|
|
|
*telegram-timeout*)))
|
|
*telegram-timeout*)))
|
|
|
(response (yason:parse
|
|
(response (yason:parse
|
|
|
- (flexi-streams:octets-to-string
|
|
|
|
|
- (handler-case
|
|
|
|
|
- (bordeaux-threads:with-timeout (timeout)
|
|
|
|
|
- (dex:post (format nil +telegram-api-format+ *telegram-token* method)
|
|
|
|
|
- :content params
|
|
|
|
|
- :use-connection-pool t
|
|
|
|
|
- :force-binary t))
|
|
|
|
|
- (bordeaux-threads:timeout (e)
|
|
|
|
|
- (declare (ignore e))
|
|
|
|
|
- (error "Timeout")))
|
|
|
|
|
- :external-format :utf8)
|
|
|
|
|
|
|
+ (flexi-streams:make-flexi-stream
|
|
|
|
|
+ (handler-case
|
|
|
|
|
+ (bordeaux-threads:with-timeout (timeout)
|
|
|
|
|
+ (drakma:http-request (format nil +telegram-api-format+
|
|
|
|
|
+ *telegram-token* method)
|
|
|
|
|
+ :method :post
|
|
|
|
|
+ :parameters params
|
|
|
|
|
+ :external-format-out :utf8
|
|
|
|
|
+ :want-stream t :force-binary t :decode-content t))
|
|
|
|
|
+ (bordeaux-threads:timeout () (error "Timeout")))
|
|
|
|
|
+ :external-format :utf8)
|
|
|
:object-as :alist)))
|
|
:object-as :alist)))
|
|
|
(unless (aget "ok" response)
|
|
(unless (aget "ok" response)
|
|
|
(error (aget "description" response)))
|
|
(error (aget "description" response)))
|