|
|
@@ -0,0 +1,32 @@
|
|
|
+(in-package #:chatikbot)
|
|
|
+
|
|
|
+(defvar *web-path* nil "Set to externally accessible url")
|
|
|
+(defvar *web-iface* nil "Interface to listen on")
|
|
|
+(defvar *web-port* 4242 "Port to listen on")
|
|
|
+
|
|
|
+(defvar *web-acceptor* nil "Running hunchentoot acceptor")
|
|
|
+
|
|
|
+(defun web-start ()
|
|
|
+ (when *web-acceptor* (hunchentoot:stop *web-acceptor*))
|
|
|
+ (when *web-path*
|
|
|
+ (setf *web-acceptor*
|
|
|
+ (hunchentoot:start
|
|
|
+ (make-instance 'hunchentoot:easy-acceptor
|
|
|
+ :address *web-iface* :port *web-port*)))))
|
|
|
+(add-hook :starting #'(lambda () (web-start) (values)))
|
|
|
+
|
|
|
+(defun webhookp (request)
|
|
|
+ (equal (concatenate 'string "/" *telegram-token*)
|
|
|
+ (hunchentoot:script-name* request)))
|
|
|
+
|
|
|
+(hunchentoot:define-easy-handler (webhook-handler :uri #'webhookp :default-request-type :post) ()
|
|
|
+ (handler-case
|
|
|
+ (let ((stream (hunchentoot:raw-post-data :want-stream t)))
|
|
|
+ (setf (flex:flexi-stream-external-format stream) :utf-8)
|
|
|
+ (handle-update (yason:parse stream :object-as :alist)))
|
|
|
+ (error (e) (log:error e))))
|
|
|
+
|
|
|
+(hunchentoot:define-easy-handler (oauth-handler :uri "/oauth")
|
|
|
+ (code state error (error-description :real-name "error_description"))
|
|
|
+ (setf (hunchentoot:content-type*) "text/plain")
|
|
|
+ (format nil "Hey~@[ ~A~]~@[ ~A~]~@[ ~A~]~@[ ~A~]!" code state error error-description))
|