Skip to content

Instantly share code, notes, and snippets.

@Shikib
Created May 20, 2020 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shikib/0fa055ac0370b969bc36b19f2dca229f to your computer and use it in GitHub Desktop.
Save Shikib/0fa055ac0370b969bc36b19f2dca229f to your computer and use it in GitHub Desktop.
DialPort Example System API
import tornado.ioloop
import tornado.web
import json
histories = {}
def reply(history):
return ' '.join(history[-1].split()[::-1])
class MainHandler(tornado.web.RequestHandler):
def set_default_headers(self):
self.set_header("Access-Control-Allow-Origin", "*")
self.set_header("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
def options(self):
pass
def post(self):
body = json.loads(self.request.body.decode())
if body["text"] == "SSTTAARRTT":
histories[body["userID"]] = []
else:
histories[body["userID"]].append(body["text"])
response = reply(histories[body["userID"]])
histories[body["userID"]].append(response)
self.write(json.dumps({"body": json.dumps({"utterance": response})}))
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8890)
tornado.ioloop.IOLoop.current().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment