matrix_chatgpt_bot/send_message.py

20 lines
701 B
Python
Raw Normal View History

2023-03-05 14:07:25 +00:00
from nio import AsyncClient
async def send_room_message(client: AsyncClient,
room_id: str,
2023-03-22 14:28:22 +00:00
send_text: str,
reply_to_event_id: str = '') -> None:
if reply_to_event_id == '':
content = {"msgtype": "m.text", "body": f"{send_text}", }
else:
content={"msgtype": "m.text", "body": f"{send_text}",
"m.relates_to": {"m.in_reply_to": {"event_id": reply_to_event_id}}, }
2023-03-05 14:07:25 +00:00
await client.room_send(
room_id,
message_type="m.room.message",
2023-03-22 14:28:22 +00:00
content=content,
2023-03-14 14:37:30 +00:00
ignore_unverified_devices=True,
2023-03-05 14:07:25 +00:00
)
await client.room_typing(room_id, typing_state=False)