Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
feature(#34 #39): updated sendNotification and response format.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas committed Jun 9, 2023
1 parent 570c75f commit f885837
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
heroku_app_name: smartphone
heroku_email: ${{ secrets.HEROKU_EMAIL }}
run: |
git remote add heroku https://heroku:${heroku_api_key}@git.heroku.com/${heroku_app_name}.git
git remote add heroku https://heroku:${{ secrets.HEROKU_API_KEY }}@git.heroku.com/smartphone.git
git config --local http.extraheader "Heroku-Space: ttt246"
git push heroku develop:master --force
Expand Down
3 changes: 1 addition & 2 deletions src/common/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def to_basic_model(self, data: Any) -> BasicModel:
"""mapping to http response"""

def to_response(self, code, message, result) -> Any:
response = jsonify({"message": message, "result": result})
response.status_code = code
response = {"message": message, "result": result, "status_code": code}
return response

"""mapping data to a collection of MessageModel"""
Expand Down
58 changes: 22 additions & 36 deletions src/router/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,31 @@ def construct_blueprint_api():
{"message": "this is test message", "token": "test_token", "uuid": "test_uuid"}
)"""

@api.route("/sendNotification", methods=["POST"])
def send_notification():
@api.route("/send", methods=["POST"])
def send_msg():
data = json.loads(request.get_data())
query = data["message"]
token = data["token"]
uuid = data["uuid"]

result = getCompletion(query=query, uuid=uuid)
result = eval(getCompletion(query=query, uuid=uuid))

# check contact querying
try:
result_json = eval(result)
if result_json["program"] == ProgramType.CONTACT:
if result["program"] == ProgramType.CONTACT:
# querying contacts to getting its expected results
contacts_results = contacts_service.query_contacts(
uuid=uuid, search=result_json["content"]
uuid=uuid, search=result["content"]
)
result_json["content"] = str(contacts_results)
result = str(result_json)
result["content"] = str(contacts_results)
except Exception as e:
logger.error(title="sendNotification", message=result)

notification = {"title": "alert", "content": result}
notification = {"title": "alert", "content": json.dumps(result)}

state, value = send_message(notification, [token])
response = jsonify({"message": value, "result": result})
response.status_code = 200
return response

return assembler.to_response(200, value, result)

"""@generator.response(
status_code=200, schema={"message": "message", "result": "test_result"}
Expand All @@ -97,9 +94,7 @@ def upload_image():
notification = {"title": "alert", "content": embed_result}

state, value = send_message(notification, [token])
response = jsonify({"message": value, "result": result})
response.status_code = 200
return response
return assembler.to_response(200, value, result)

"""@generator.response(
status_code=200, schema={"message": "message", "result": "test_result"}
Expand Down Expand Up @@ -137,19 +132,14 @@ def image_relatedness():

notification = {"title": "alert", "content": json.dumps(image_response)}
state, value = send_message(notification, [token])
response = jsonify(
return assembler.to_response(
200,
value,
{
"message": value,
"result": json.dumps(
{
"program": "image",
"content": json.dumps(image_response),
}
),
}
"program": "image",
"content": image_response,
},
)
response.status_code = 200
return response

@api.route("/file/<string:filename>")
def get_swagger_file(filename):
Expand Down Expand Up @@ -207,7 +197,7 @@ def add_feedback():
@api.route("/feedback/<string:search>/<int:rating>")
def get_feedback(search, rating):
result = feedback_service.get(search, rating)
return assembler.to_response(200, "added successfully", json.dumps(result))
return assembler.to_response(200, "added successfully", result)

"""@generator.response(
status_code=200, schema={"message": "message", "result": "test_result"}
Expand All @@ -219,7 +209,7 @@ def get_commands():
return assembler.to_response(
200,
"success",
json.dumps({"program": "help_command", "content": json.dumps(result)}),
{"program": "help_command", "content": result},
)

"""@generator.request_body(
Expand Down Expand Up @@ -267,14 +257,10 @@ def message_agent():
return assembler.to_response(
200,
"added successfully",
json.dumps(
{
"program": "agent",
"message": json.dumps(
assistant_reply.get_one_message_item().to_json()
),
}
),
{
"program": "agent",
"message": assistant_reply.get_one_message_item().to_json(),
},
)

"""@generator.request_body(
Expand Down

0 comments on commit f885837

Please sign in to comment.