Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions app.py
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
Copy link
Contributor

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?

from flask import request
from flask import make_response

# Flask app should start in global layout
app = Flask(__name__)


Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for debugging purpose, please remove before merging

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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


Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these are not used, remove

# "contextOut": [],
}

Copy link
Contributor

Choose a reason for hiding this comment

The 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')
Binary file added webhook_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.