Implement executing tasks
This commit is contained in:
@@ -193,6 +193,28 @@ def _extract_signal_reaction(envelope):
|
||||
}
|
||||
|
||||
|
||||
def _extract_signal_text(raw_payload, default_text=""):
|
||||
text = str(default_text or "").strip()
|
||||
if text:
|
||||
return text
|
||||
payload = dict(raw_payload or {})
|
||||
envelope = dict(payload.get("envelope") or {})
|
||||
candidates = [
|
||||
envelope.get("dataMessage"),
|
||||
_get_nested(envelope, ("syncMessage", "sentMessage", "message")),
|
||||
_get_nested(envelope, ("syncMessage", "sentMessage")),
|
||||
payload.get("dataMessage"),
|
||||
payload,
|
||||
]
|
||||
for item in candidates:
|
||||
if isinstance(item, dict):
|
||||
for key in ("message", "text", "body", "caption"):
|
||||
value = str(item.get(key) or "").strip()
|
||||
if value:
|
||||
return value
|
||||
return ""
|
||||
|
||||
|
||||
def _typing_started(typing_payload):
|
||||
action = str(typing_payload.get("action") or "").strip().lower()
|
||||
if action in {"started", "start", "typing", "composing"}:
|
||||
@@ -368,6 +390,7 @@ class HandleMessage(Command):
|
||||
source_number = c.message.source_number
|
||||
source_uuid = c.message.source_uuid
|
||||
text = c.message.text
|
||||
text = _extract_signal_text(raw, text)
|
||||
ts = c.message.timestamp
|
||||
source_value = c.message.source
|
||||
envelope = raw.get("envelope", {})
|
||||
@@ -1209,14 +1232,17 @@ class SignalClient(ClientBase):
|
||||
if isinstance(sync_sent_message, dict) and sync_sent_message:
|
||||
raw_text = sync_sent_message.get("message")
|
||||
if isinstance(raw_text, dict):
|
||||
text = str(
|
||||
raw_text.get("message")
|
||||
or raw_text.get("text")
|
||||
or raw_text.get("body")
|
||||
or ""
|
||||
).strip()
|
||||
text = _extract_signal_text(
|
||||
{"envelope": {"syncMessage": {"sentMessage": {"message": raw_text}}}},
|
||||
str(
|
||||
raw_text.get("message")
|
||||
or raw_text.get("text")
|
||||
or raw_text.get("body")
|
||||
or ""
|
||||
).strip(),
|
||||
)
|
||||
else:
|
||||
text = str(raw_text or "").strip()
|
||||
text = _extract_signal_text(payload, str(raw_text or "").strip())
|
||||
|
||||
destination_uuid = str(
|
||||
sync_sent_message.get("destinationUuid")
|
||||
@@ -1373,7 +1399,7 @@ class SignalClient(ClientBase):
|
||||
)
|
||||
return
|
||||
|
||||
text = str(data_message.get("message") or "").strip()
|
||||
text = _extract_signal_text(payload, str(data_message.get("message") or "").strip())
|
||||
if not text:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user