improve message sending

This commit is contained in:
saces 2026-02-06 18:34:15 +01:00
parent f3cde63e37
commit b6ee0f901e
4 changed files with 29 additions and 13 deletions

View file

@ -48,7 +48,13 @@ class DemoBot(SMALBot):
if msg["content"]["body"].startswith("!echo"):
logger.error(f"reply to this: {msg}")
self.sendmessage(msg["roomid"], "huhu")
txt = msg["content"]["body"][5:].strip()
if txt.strip() == "":
txt = "Are you kidding me?"
# self.sendmessage(msg["roomid"], txt)
self.sendmessagereply(msg["roomid"], msg["id"], msg["sender"], txt)
return

View file

@ -30,5 +30,22 @@ class SMALBot(SMALApp):
data["roomid"] = roomid
data["content"] = {}
data["content"]["body"] = text
data["content"]["msgtype"] = "m.text"
self._sendmessage(data)
def sendmessagereply(self, roomid, msgid, mxid, text):
data = {}
data["roomid"] = roomid
data["content"] = {}
data["content"]["body"] = text
data["content"]["msgtype"] = "m.text"
data["content"]["m.mentions"] = {}
data["content"]["m.mentions"]["user_ids"] = [
mxid,
]
data["content"]["m.relates_to"] = {}
data["content"]["m.relates_to"]["m.in_reply_to"] = {}
data["content"]["m.relates_to"]["m.in_reply_to"]["event_id"] = msgid
self._sendmessage(data)

View file

@ -74,11 +74,8 @@ class _MXClient:
def _sendmessage(self, data_dict):
data = json.dumps(data_dict).encode(encoding="utf-8")
r = lib.apiv0_sendmessage(self.client_id, data)
result = ffi.string(r)
lib.FreeCString(r)
# if result.startswith(b"ERR:"):
# raise APIError(result)
print("_sendmessage: ", result)
result = checkApiError(r)
return result
def process_event(self, evt):
if hasattr(self, "on_event") and callable(self.on_event):