Extract function to send message
Merges duplicated code.
This commit is contained in:
parent
cf054631e8
commit
54baf29d51
1 changed files with 9 additions and 6 deletions
|
@ -51,20 +51,23 @@ async def handler(request):
|
|||
"formatted_body": markdown(data['text'], extensions=['extra']),
|
||||
}
|
||||
try:
|
||||
await CLIENT.room_send(room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content=content)
|
||||
await send_room_message(room_id, content)
|
||||
except LocalProtocolError: # Connection lost, try another login
|
||||
await CLIENT.login(MATRIX_PW)
|
||||
await CLIENT.room_send(room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content=content)
|
||||
await send_room_message(room_id, content)
|
||||
|
||||
return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret),
|
||||
content_type='application/json',
|
||||
status=status)
|
||||
|
||||
|
||||
async def send_room_message(room_id, content):
|
||||
"""Send a message to a room."""
|
||||
return await CLIENT.room_send(room_id=room_id,
|
||||
message_type='m.room.message',
|
||||
content=content)
|
||||
|
||||
|
||||
async def main(event):
|
||||
"""
|
||||
Launch main coroutine.
|
||||
|
|
Loading…
Reference in a new issue