2016-08-23 18:35:47 +00:00
|
|
|
from helpers import requestHelper
|
2016-08-17 14:41:05 +00:00
|
|
|
from constants import exceptions
|
|
|
|
import json
|
|
|
|
from objects import glob
|
|
|
|
from helpers import chatHelper
|
2016-08-23 18:35:47 +00:00
|
|
|
from helpers import logHelper as log
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
class handler(requestHelper.asyncRequestHandler):
|
|
|
|
def asyncGet(self):
|
|
|
|
statusCode = 400
|
|
|
|
data = {"message": "unknown error"}
|
|
|
|
try:
|
|
|
|
# Check arguments
|
|
|
|
if requestHelper.checkArguments(self.request.arguments, ["k", "to", "msg"]) == False:
|
|
|
|
raise exceptions.invalidArgumentsException()
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Check ci key
|
|
|
|
key = self.get_argument("k")
|
|
|
|
if key is None or key != glob.conf.config["server"]["cikey"]:
|
|
|
|
raise exceptions.invalidArgumentsException()
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
log.info("API REQUEST FOR FOKABOT MESSAGE AAAAAAA")
|
|
|
|
chatHelper.sendMessage("FokaBot", self.get_argument("to"), self.get_argument("msg"))
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Status code and message
|
|
|
|
statusCode = 200
|
|
|
|
data["message"] = "ok"
|
|
|
|
except exceptions.invalidArgumentsException:
|
|
|
|
statusCode = 400
|
|
|
|
data["message"] = "invalid parameters"
|
|
|
|
finally:
|
|
|
|
# Add status code to data
|
|
|
|
data["status"] = statusCode
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Send response
|
|
|
|
#self.clear()
|
|
|
|
self.write(json.dumps(data))
|
|
|
|
self.set_status(statusCode)
|
|
|
|
#self.finish(json.dumps(data))
|