diff --git a/app/app.py b/app/app.py index 1333743eb3816882be5f05679efc8575e0533670..2bd6fad5e4299b859fef14341a9f3ef322277c95 100644 --- a/app/app.py +++ b/app/app.py @@ -1,5 +1,8 @@ from flask import Flask from flask import render_template +from flask import request +from flask import jsonify +import requests app = Flask(__name__) @@ -7,5 +10,22 @@ app = Flask(__name__) def home(): return render_template("index.html") +@app.route('/sendmessage', methods=['POST']) +def sendmessage(): + message = request.form['message'] + print(message) + rasa_response = requests.post('http://localhost:5005/webhooks/rest/webhook', json={"message": message}) + + responses = [] + for resp in rasa_response.json(): + if "text" in resp: + responses.append({"type": "text", "content": resp["text"]}) + if "image" in resp: + responses.append({"type": "image", "content": resp["image"]}) + if "buttons" in resp: + responses.append({"type": "buttons", "content": resp["buttons"]}) + + return jsonify(responses) + if __name__ == '__main__': app.run(debug=True) diff --git a/app/static/javascript/frontend.js b/app/static/javascript/frontend.js new file mode 100644 index 0000000000000000000000000000000000000000..3a11f097f29e0bc15ecb1444fc17eff0765704d9 --- /dev/null +++ b/app/static/javascript/frontend.js @@ -0,0 +1,15 @@ +function sendMessage() { + message = document.getElementById("inputField").value; + message = "message=" + message; + fetch("http://localhost:5000/sendmessage", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: message + }) + .then((response) => response.json()) + .then((json) => { + console.log(json[0].content); + }); +}; \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index 91f0930d43cf341dd8620a1d19a78e24bb7eb53d..19301a4a250b1bb74af553f5bb4ab50dbeaf0101 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -8,5 +8,10 @@ <body> <h1>Welcome to the Space Station Chatbot!</h1> + <div> + <input type="text" id="inputField" placeholder="Gib etwas ein"> + <button onclick="sendMessage()">CLICK ME</button> + </div> + <script src="static/javascript/frontend.js" type="application/javascript"></script> </body> </html> \ No newline at end of file diff --git a/rasa/endpoints.yml b/rasa/endpoints.yml index 1128e1d53e27d2990f85561c5317e8d3df3b6e2a..5f65275b8802fb69860a6083011dab7e70586e66 100644 --- a/rasa/endpoints.yml +++ b/rasa/endpoints.yml @@ -10,8 +10,8 @@ # Server which runs your custom actions. # https://rasa.com/docs/rasa/custom-actions -#action_endpoint: -# url: "http://localhost:5055/webhook" +action_endpoint: + url: "http://localhost:5055/webhook" # Tracker store which is used to store the conversations. # By default the conversations are stored in memory.