Skip to content

Commit

Permalink
Test Server (#79)
Browse files Browse the repository at this point in the history
* Add test_server.py

* Add test_interface.html

* Update .gitignore
  • Loading branch information
justinh-rahb authored Sep 3, 2023
1 parent 0664289 commit f2a1996
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ cython_debug/
#.idea/

.DS_Store
.env

# Docs site
_site/
.sass-cache/
.jekyll-cache/
.jekyll-metadata
.bundle/
vendor/
vendor/
46 changes: 46 additions & 0 deletions test_interface.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat²GPT Test Rig</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>Chat²GPT Test Rig</h1>
<form id="userForm">
<label for="userInput">Enter your message or command:</label><br>
<input type="text" id="userInput" name="userInput" required><br><br>
<input type="submit" value="Send">
</form>
<div id="responseContainer">
<!-- The server response will be displayed here -->
</div>
<script>
$("#userForm").submit(function(e) {
e.preventDefault();
const userInput = $("#userInput").val();
const wrappedEventData = {
"type": "MESSAGE",
"user": { "name": "users/simulated" },
"message": { "text": userInput }
};
$.ajax({
url: "/post",
type: "POST",
data: JSON.stringify(wrappedEventData),
contentType: "application/json",
success: function(response) {
// Handle the response
console.log(response);
$("#responseContainer").html("Server Response: " + JSON.stringify(response));
},
error: function(error) {
// Handle the error
console.log(error);
$("#responseContainer").html("Error: " + JSON.stringify(error));
}
});
});
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from flask import Flask, request, jsonify, send_from_directory
from main import process_event
import json

app = Flask(__name__, static_url_path='', static_folder='.')

@app.route('/')
def root():
return send_from_directory('.', 'test_interface.html')

@app.route('/post', methods=['POST'])
def google_chat_event():
try:
# Debug: Print the raw request data
print("Raw Request Data:", request.data)

# Get the event data from the request body
response = process_event(request)
return response
except Exception as e:
return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
app.run(port=5000, debug=True)

0 comments on commit f2a1996

Please sign in to comment.