mirror of
https://github.com/bsedin/matrix-webhook.git
synced 2026-04-09 19:35:39 +00:00
Use aiohttp.web.json_response()
Avoids explicit setting of JSON content type, handles serialization to JSON.
This commit is contained in:
@@ -56,9 +56,13 @@ async def handler(request):
|
|||||||
await CLIENT.login(MATRIX_PW)
|
await CLIENT.login(MATRIX_PW)
|
||||||
await send_room_message(room_id, content)
|
await send_room_message(room_id, content)
|
||||||
|
|
||||||
return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret),
|
return create_json_response(status, ret)
|
||||||
content_type='application/json',
|
|
||||||
status=status)
|
|
||||||
|
def create_json_response(status, ret):
|
||||||
|
"""Create a JSON response."""
|
||||||
|
response_data = {'status': status, 'ret': ret}
|
||||||
|
return web.json_response(response_data, status=status)
|
||||||
|
|
||||||
|
|
||||||
async def send_room_message(room_id, content):
|
async def send_room_message(room_id, content):
|
||||||
|
|||||||
Reference in New Issue
Block a user