Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Server #79

Merged
merged 10 commits into from
Sep 3, 2023
Merged
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
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)