You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

5 years ago
  1. import os
  2. from flask import Flask, jsonify, request, json
  3. app = Flask(__name__)
  4. @app.route('/qa_bot/fulfillment', methods=['GET', 'POST'])
  5. def index():
  6. jsonObj = request.get_json()
  7. # print(type(jsonObj))
  8. # print(jsonObj)
  9. print('responseId => {},\n session => {}'.format(jsonObj.get('responseId'),jsonObj.get('session')))
  10. print(request.get_data(as_text=True))
  11. return sample_response()
  12. def sample_response():
  13. strRes = ''
  14. jsonResp = {
  15. 'fulfillmentText':'超級帥哥Richard',
  16. 'fulfillmentMessages': [
  17. # {
  18. # 'image' : {
  19. # 'imageUri':'https://yt3.ggpht.com/a/AGF-l78sCrWnJHZlRs-DP1imkaINg2KkpT5Gomkahw=s900-mo-c-c0xffffffff-rj-k-no',
  20. # 'accessibilityText':'Hello World!!'
  21. # }
  22. # }
  23. # {
  24. # 'card': {
  25. # 'title': 'card title',
  26. # 'subtitle': 'card text',
  27. # 'imageUri': 'https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png',
  28. # 'buttons': [
  29. # {
  30. # 'text': 'button text',
  31. # 'postback': 'https://assistant.google.com/'
  32. # }
  33. # ]
  34. # }
  35. # }
  36. ],
  37. 'source':'richard-shih.idv.tw'
  38. }
  39. return jsonify(jsonResp)
  40. def main():
  41. port = os.environ.get('FLASK_EXPOSE_PORT')
  42. port = port if port != None else 8080
  43. app.run(host='0.0.0.0', port=port, debug=True)
  44. if __name__ == '__main__':
  45. main()