-
Notifications
You must be signed in to change notification settings - Fork 0
Servertest 003 : Chatbot <-> Flask Web server #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| from __future__ import print_function | ||
|
|
||
| from urllib.parse import urlparse, urlencode | ||
| from urllib.request import urlopen, Request | ||
| from urllib.error import HTTPError | ||
|
|
||
| import requests | ||
| import json | ||
| import os | ||
|
|
||
| from flask import Flask | ||
| from flask import request | ||
| from flask import make_response | ||
|
|
||
| # Flask app should start in global layout | ||
| app = Flask(__name__) | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line |
||
| @app.route('/webhook', methods=['POST']) | ||
| def webhook(): | ||
| req = request.get_json(silent=True, force=True) | ||
| print("Request:") | ||
| print(json.dumps(req, indent=4)) | ||
|
|
||
| res = processRequest(req) | ||
| res = json.dumps(res, indent=4) | ||
| print(res) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is for debugging purpose, please remove before merging
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is necessary, please add your justification as a comment |
||
| r = make_response(res) | ||
| r.headers['Content-Type'] = 'application/json' | ||
| return r | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line |
||
|
|
||
| def processRequest(req): | ||
| if req.get("result").get("action") != "search": | ||
| return {} | ||
| testret = requests.get("https://api.korbit.co.kr/v1/ticker") | ||
| testdata = testret.json()['last'] # It's just test data. | ||
|
|
||
| res = makeWebhookResult(testdata) | ||
| return res | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line |
||
| def makeWebhookResult(data): | ||
| result = data | ||
| speech = "result : " + result | ||
|
|
||
| print("Response:") | ||
| print(speech) | ||
|
|
||
| return { | ||
| "speech": speech, | ||
| "displayText": speech, | ||
| # "data": data, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if these are not used, remove |
||
| # "contextOut": [], | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line |
||
|
|
||
| if __name__ == '__main__': | ||
| port = int(os.getenv('PORT', 5000)) | ||
|
|
||
| print("Starting app on port %d" % port) | ||
|
|
||
| app.run(debug=False, port=port, host='0.0.0.0') | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think it's possible to group 'from's together? and maybe alphabetical order?