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']),
|
"formatted_body": markdown(data['text'], extensions=['extra']),
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
await CLIENT.room_send(room_id=room_id,
|
await send_room_message(room_id, content)
|
||||||
message_type="m.room.message",
|
|
||||||
content=content)
|
|
||||||
except LocalProtocolError: # Connection lost, try another login
|
except LocalProtocolError: # Connection lost, try another login
|
||||||
await CLIENT.login(MATRIX_PW)
|
await CLIENT.login(MATRIX_PW)
|
||||||
await CLIENT.room_send(room_id=room_id,
|
await send_room_message(room_id, content)
|
||||||
message_type="m.room.message",
|
|
||||||
content=content)
|
|
||||||
|
|
||||||
return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret),
|
return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
status=status)
|
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):
|
async def main(event):
|
||||||
"""
|
"""
|
||||||
Launch main coroutine.
|
Launch main coroutine.
|
||||||
|
|
Loading…
Reference in a new issue