| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- (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 *random-state* (make-random-state 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 error state)
- (handler-case
- (run-hooks :oauth code error state)
- (error (e)
- (log:error e)
- (hunchentoot:redirect "/error"))))
- (hunchentoot:define-easy-handler (error-handler :uri "/error") ()
- "<html>
- <head><title>Internal error</title></head>
- <body>
- <h1>Error :'(</h1>
- <p>Internal server error</p>
- </html>")
- (hunchentoot:define-easy-handler (oauth-success-handler :uri "/oauth/success") ()
- "<html>
- <head><title>Auth Success</title></head>
- <body>
- <h1>Success!</h1>
- <p>OAuth successfully completed. You could close this tab and go back to telegram bot</p>
- </html>")
- (hunchentoot:define-easy-handler (oauth-fail-handler :uri "/oauth/fail") ()
- "<html>
- <head><title>Auth failed</title></head>
- <body>
- <h1>Failed :(</h1>
- <p>OAuth failed. You probably didn't allow the access. Try again.</p>
- </html>")
|