-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test_server.py * Add test_interface.html * Update .gitignore
- Loading branch information
1 parent
0664289
commit f2a1996
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |