Skip to content
Snippets Groups Projects
Commit 4bb59533 authored by Dominic Daniel Krämer's avatar Dominic Daniel Krämer
Browse files

add basic integration into html

parent 13835660
No related branches found
No related tags found
No related merge requests found
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)
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
......@@ -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
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment