shellzapy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shellzapy-0.1.0.dist-info/METADATA +112 -0
- shellzapy-0.1.0.dist-info/RECORD +345 -0
- shellzapy-0.1.0.dist-info/WHEEL +4 -0
- shellzapy-0.1.0.dist-info/licenses/LICENSE +21 -0
- shellzapy-0.1.0.dist-info/licenses/NOTICE +9 -0
- zapy/__init__.py +58 -0
- zapy/_appstate/__init__.py +59 -0
- zapy/_appstate/constants.py +82 -0
- zapy/_appstate/crypto/__init__.py +17 -0
- zapy/_appstate/crypto/app_state_crypto.py +401 -0
- zapy/_appstate/parsers/__init__.py +23 -0
- zapy/_appstate/parsers/encoding.py +157 -0
- zapy/_appstate/parsers/response_parser.py +135 -0
- zapy/_appstate/sync/__init__.py +11 -0
- zapy/_appstate/sync/sync_client.py +1559 -0
- zapy/_appstate/types.py +137 -0
- zapy/_appstate/utils.py +100 -0
- zapy/_auth/__init__.py +3 -0
- zapy/_auth/auth_client.py +618 -0
- zapy/_auth/credentials_flow.py +290 -0
- zapy/_auth/pairing/__init__.py +3 -0
- zapy/_auth/pairing/companion_host.py +239 -0
- zapy/_auth/pairing/flow.py +808 -0
- zapy/_auth/pairing/pairing_code_crypto.py +143 -0
- zapy/_auth/pairing/qr_flow.py +123 -0
- zapy/_auth/pairing/shortcake_crypto.py +122 -0
- zapy/_auth/pairing/shortcake_flow.py +393 -0
- zapy/_auth/types.py +110 -0
- zapy/_client/__init__.py +26 -0
- zapy/_client/client.py +972 -0
- zapy/_client/connection/__init__.py +6 -0
- zapy/_client/connection/manager.py +525 -0
- zapy/_client/connection/receipt_queue.py +74 -0
- zapy/_client/coordinators/__init__.py +81 -0
- zapy/_client/coordinators/ab_props.py +260 -0
- zapy/_client/coordinators/app_state_mutation.py +2538 -0
- zapy/_client/coordinators/bot.py +830 -0
- zapy/_client/coordinators/broadcast_list.py +101 -0
- zapy/_client/coordinators/business.py +247 -0
- zapy/_client/coordinators/email.py +158 -0
- zapy/_client/coordinators/group.py +1478 -0
- zapy/_client/coordinators/incoming_node.py +758 -0
- zapy/_client/coordinators/low_level.py +119 -0
- zapy/_client/coordinators/message.py +1153 -0
- zapy/_client/coordinators/message_dispatch.py +1637 -0
- zapy/_client/coordinators/newsletter.py +110 -0
- zapy/_client/coordinators/offline_resume.py +271 -0
- zapy/_client/coordinators/passive_tasks.py +447 -0
- zapy/_client/coordinators/presence.py +103 -0
- zapy/_client/coordinators/privacy.py +623 -0
- zapy/_client/coordinators/profile.py +1024 -0
- zapy/_client/coordinators/retry.py +1878 -0
- zapy/_client/coordinators/status.py +132 -0
- zapy/_client/coordinators/stream_control.py +260 -0
- zapy/_client/coordinators/trusted_contact_token.py +417 -0
- zapy/_client/events/__init__.py +266 -0
- zapy/_client/events/abprops.py +58 -0
- zapy/_client/events/appstate_mutation.py +248 -0
- zapy/_client/events/business.py +565 -0
- zapy/_client/events/call.py +144 -0
- zapy/_client/events/chatstate.py +41 -0
- zapy/_client/events/devices.py +122 -0
- zapy/_client/events/dirty.py +384 -0
- zapy/_client/events/group.py +655 -0
- zapy/_client/events/identity.py +40 -0
- zapy/_client/events/incoming.py +1079 -0
- zapy/_client/events/mex_notification.py +317 -0
- zapy/_client/events/offline.py +123 -0
- zapy/_client/events/picture.py +67 -0
- zapy/_client/events/presence.py +74 -0
- zapy/_client/events/privacy.py +187 -0
- zapy/_client/events/privacy_token.py +72 -0
- zapy/_client/events/receipt.py +109 -0
- zapy/_client/events/registration.py +70 -0
- zapy/_client/events/username.py +76 -0
- zapy/_client/factory.py +2020 -0
- zapy/_client/media.py +829 -0
- zapy/_client/newsletter/__init__.py +90 -0
- zapy/_client/newsletter/admin.py +323 -0
- zapy/_client/newsletter/content.py +499 -0
- zapy/_client/newsletter/discovery.py +233 -0
- zapy/_client/newsletter/messaging.py +396 -0
- zapy/_client/newsletter/mex.py +99 -0
- zapy/_client/newsletter/parse.py +406 -0
- zapy/_client/newsletter/types.py +393 -0
- zapy/_client/persistence/__init__.py +89 -0
- zapy/_client/persistence/companion_host.py +133 -0
- zapy/_client/persistence/ephemeral_setting.py +245 -0
- zapy/_client/persistence/group_history.py +361 -0
- zapy/_client/persistence/history_blob.py +169 -0
- zapy/_client/persistence/history_sync.py +646 -0
- zapy/_client/persistence/mailbox.py +232 -0
- zapy/_client/persistence/write_behind_persistence.py +368 -0
- zapy/_client/plugins/__init__.py +23 -0
- zapy/_client/plugins/define.py +44 -0
- zapy/_client/plugins/install.py +254 -0
- zapy/_client/plugins/types.py +64 -0
- zapy/_client/tokens/__init__.py +21 -0
- zapy/_client/tokens/cs_token.py +47 -0
- zapy/_client/tokens/tc_token.py +43 -0
- zapy/_client/types.py +988 -0
- zapy/_crypto/__init__.py +65 -0
- zapy/_crypto/core/__init__.py +62 -0
- zapy/_crypto/core/hkdf.py +41 -0
- zapy/_crypto/core/keys.py +51 -0
- zapy/_crypto/core/nonce.py +25 -0
- zapy/_crypto/core/primitives.py +179 -0
- zapy/_crypto/core/random.py +32 -0
- zapy/_crypto/core/xeddsa.py +72 -0
- zapy/_crypto/curves/__init__.py +3 -0
- zapy/_crypto/curves/constants.py +10 -0
- zapy/_crypto/curves/ed25519.py +61 -0
- zapy/_crypto/curves/types.py +18 -0
- zapy/_crypto/curves/x25519.py +117 -0
- zapy/_crypto/math/__init__.py +3 -0
- zapy/_crypto/math/constants.py +35 -0
- zapy/_crypto/math/edwards.py +174 -0
- zapy/_crypto/math/fe.py +120 -0
- zapy/_crypto/math/le.py +13 -0
- zapy/_crypto/math/mod.py +15 -0
- zapy/_crypto/math/prime.py +11 -0
- zapy/_crypto/math/types.py +25 -0
- zapy/_crypto/native_backend.py +40 -0
- zapy/_infra/__init__.py +3 -0
- zapy/_infra/log.py +142 -0
- zapy/_infra/perf.py +77 -0
- zapy/_media/__init__.py +64 -0
- zapy/_media/constants.py +133 -0
- zapy/_media/container.py +110 -0
- zapy/_media/crypto/__init__.py +19 -0
- zapy/_media/crypto/crypto.py +633 -0
- zapy/_media/crypto/media_retry.py +107 -0
- zapy/_media/processor.py +100 -0
- zapy/_media/sticker/__init__.py +8 -0
- zapy/_media/sticker/pack.py +188 -0
- zapy/_media/transfer/__init__.py +15 -0
- zapy/_media/transfer/client.py +635 -0
- zapy/_media/transfer/conn.py +48 -0
- zapy/_media/types.py +169 -0
- zapy/_message/__init__.py +121 -0
- zapy/_message/addons/__init__.py +5 -0
- zapy/_message/addons/link_preview/__init__.py +54 -0
- zapy/_message/addons/link_preview/builder.py +56 -0
- zapy/_message/addons/link_preview/detect.py +72 -0
- zapy/_message/addons/link_preview/fetcher.py +553 -0
- zapy/_message/addons/link_preview/types.py +100 -0
- zapy/_message/client.py +486 -0
- zapy/_message/context_info.py +424 -0
- zapy/_message/crypto/__init__.py +71 -0
- zapy/_message/crypto/addon_crypto.py +656 -0
- zapy/_message/crypto/icdc.py +138 -0
- zapy/_message/crypto/phash.py +87 -0
- zapy/_message/crypto/reporting_token.py +498 -0
- zapy/_message/crypto/use_case_secret.py +113 -0
- zapy/_message/encode/__init__.py +84 -0
- zapy/_message/encode/content.py +636 -0
- zapy/_message/encode/device_sent.py +88 -0
- zapy/_message/encode/media_payload.py +122 -0
- zapy/_message/encode/padding.py +27 -0
- zapy/_message/kinds/__init__.py +1 -0
- zapy/_message/kinds/bot.py +179 -0
- zapy/_message/kinds/group_history.py +206 -0
- zapy/_message/kinds/newsletter.py +388 -0
- zapy/_message/kinds/sticker_pack.py +74 -0
- zapy/_message/messaging/__init__.py +336 -0
- zapy/_message/messaging/companion_host.py +117 -0
- zapy/_message/messaging/fanout.py +311 -0
- zapy/_message/messaging/group_metadata.py +444 -0
- zapy/_message/messaging/ignore_key.py +264 -0
- zapy/_message/messaging/key_protocol.py +217 -0
- zapy/_message/messaging/link_preview.py +448 -0
- zapy/_message/messaging/messages.py +1429 -0
- zapy/_message/primitives/__init__.py +1 -0
- zapy/_message/primitives/ack.py +232 -0
- zapy/_message/primitives/incoming.py +1141 -0
- zapy/_message/primitives/media_retry.py +451 -0
- zapy/_message/primitives/peer_data_operation.py +271 -0
- zapy/_message/types.py +434 -0
- zapy/_proto/WAProto_pb2.py +2584 -0
- zapy/_proto/__init__.py +1 -0
- zapy/_protocol/__init__.py +3 -0
- zapy/_protocol/abprops_spec.py +6216 -0
- zapy/_protocol/auth.py +17 -0
- zapy/_protocol/browser.py +57 -0
- zapy/_protocol/defaults.py +38 -0
- zapy/_protocol/device_identity.py +54 -0
- zapy/_protocol/jid.py +241 -0
- zapy/_protocol/message.py +127 -0
- zapy/_protocol/nodes.py +144 -0
- zapy/_protocol/notification.py +18 -0
- zapy/_retry/__init__.py +77 -0
- zapy/_retry/codec.py +209 -0
- zapy/_retry/constants.py +28 -0
- zapy/_retry/parse.py +132 -0
- zapy/_retry/reason.py +65 -0
- zapy/_retry/replay.py +483 -0
- zapy/_retry/tracker.py +161 -0
- zapy/_retry/types.py +122 -0
- zapy/_signal/__init__.py +171 -0
- zapy/_signal/api/__init__.py +133 -0
- zapy/_signal/api/codec.py +164 -0
- zapy/_signal/api/constants.py +14 -0
- zapy/_signal/api/device_sync.py +915 -0
- zapy/_signal/api/digest_sync.py +363 -0
- zapy/_signal/api/identity_sync.py +250 -0
- zapy/_signal/api/missing_pre_keys_sync.py +267 -0
- zapy/_signal/api/prekeys.py +191 -0
- zapy/_signal/api/result_map.py +40 -0
- zapy/_signal/api/rotate_key.py +111 -0
- zapy/_signal/api/session_sync.py +297 -0
- zapy/_signal/attestation.py +145 -0
- zapy/_signal/constants.py +22 -0
- zapy/_signal/encoding.py +78 -0
- zapy/_signal/group/__init__.py +35 -0
- zapy/_signal/group/chain.py +139 -0
- zapy/_signal/group/codec.py +78 -0
- zapy/_signal/group/encoding.py +166 -0
- zapy/_signal/group/manager.py +361 -0
- zapy/_signal/registration/__init__.py +44 -0
- zapy/_signal/registration/keygen.py +46 -0
- zapy/_signal/registration/reg_encoding.py +66 -0
- zapy/_signal/registration/reg_utils.py +52 -0
- zapy/_signal/session/__init__.py +114 -0
- zapy/_signal/session/encoding.py +385 -0
- zapy/_signal/session/protocol.py +590 -0
- zapy/_signal/session/ratchet.py +381 -0
- zapy/_signal/session/resolver.py +630 -0
- zapy/_signal/session/serializer.py +96 -0
- zapy/_signal/session/session.py +272 -0
- zapy/_signal/types.py +214 -0
- zapy/_store/__init__.py +118 -0
- zapy/_store/cache/__init__.py +166 -0
- zapy/_store/cache/identity.py +130 -0
- zapy/_store/cache/privacy_token.py +116 -0
- zapy/_store/cache/sender_key.py +168 -0
- zapy/_store/cache/session.py +142 -0
- zapy/_store/contracts/__init__.py +84 -0
- zapy/_store/contracts/appstate.py +82 -0
- zapy/_store/contracts/auth.py +16 -0
- zapy/_store/contracts/chat_metadata.py +29 -0
- zapy/_store/contracts/contact.py +31 -0
- zapy/_store/contracts/device_list.py +35 -0
- zapy/_store/contracts/group_metadata.py +33 -0
- zapy/_store/contracts/identity.py +18 -0
- zapy/_store/contracts/message.py +36 -0
- zapy/_store/contracts/message_secret.py +41 -0
- zapy/_store/contracts/pre_key.py +32 -0
- zapy/_store/contracts/privacy_token.py +32 -0
- zapy/_store/contracts/retry.py +47 -0
- zapy/_store/contracts/sender_key.py +37 -0
- zapy/_store/contracts/session.py +21 -0
- zapy/_store/contracts/signal.py +23 -0
- zapy/_store/contracts/thread.py +35 -0
- zapy/_store/create_store.py +890 -0
- zapy/_store/locks.py +1154 -0
- zapy/_store/memory/__init__.py +40 -0
- zapy/_store/memory/appstate.py +200 -0
- zapy/_store/memory/auth.py +24 -0
- zapy/_store/memory/chat_metadata.py +124 -0
- zapy/_store/memory/contact.py +125 -0
- zapy/_store/memory/device_list.py +161 -0
- zapy/_store/memory/group_metadata.py +125 -0
- zapy/_store/memory/identity.py +86 -0
- zapy/_store/memory/message.py +85 -0
- zapy/_store/memory/message_secret.py +145 -0
- zapy/_store/memory/pre_key.py +112 -0
- zapy/_store/memory/privacy_token.py +103 -0
- zapy/_store/memory/retry.py +250 -0
- zapy/_store/memory/sender_key.py +162 -0
- zapy/_store/memory/session.py +111 -0
- zapy/_store/memory/signal.py +45 -0
- zapy/_store/memory/thread.py +66 -0
- zapy/_store/noop.py +279 -0
- zapy/_transport/__init__.py +3 -0
- zapy/_transport/binary/__init__.py +77 -0
- zapy/_transport/binary/constants.py +80 -0
- zapy/_transport/binary/decoder.py +260 -0
- zapy/_transport/binary/encoder.py +279 -0
- zapy/_transport/binary/tokens.py +1289 -0
- zapy/_transport/comms.py +759 -0
- zapy/_transport/keepalive/__init__.py +3 -0
- zapy/_transport/keepalive/keep_alive.py +252 -0
- zapy/_transport/node/__init__.py +3 -0
- zapy/_transport/node/builders/__init__.py +9 -0
- zapy/_transport/node/builders/abprops.py +33 -0
- zapy/_transport/node/builders/account_sync.py +120 -0
- zapy/_transport/node/builders/bot.py +56 -0
- zapy/_transport/node/builders/business.py +261 -0
- zapy/_transport/node/builders/chatstate.py +74 -0
- zapy/_transport/node/builders/community.py +116 -0
- zapy/_transport/node/builders/device.py +30 -0
- zapy/_transport/node/builders/email.py +181 -0
- zapy/_transport/node/builders/global_.py +74 -0
- zapy/_transport/node/builders/group.py +279 -0
- zapy/_transport/node/builders/media.py +21 -0
- zapy/_transport/node/builders/message.py +436 -0
- zapy/_transport/node/builders/mobile.py +227 -0
- zapy/_transport/node/builders/newsletter.py +293 -0
- zapy/_transport/node/builders/offline.py +20 -0
- zapy/_transport/node/builders/pairing.py +130 -0
- zapy/_transport/node/builders/passive.py +28 -0
- zapy/_transport/node/builders/prekeys.py +215 -0
- zapy/_transport/node/builders/presence.py +100 -0
- zapy/_transport/node/builders/privacy.py +243 -0
- zapy/_transport/node/builders/privacy_token.py +94 -0
- zapy/_transport/node/builders/profile.py +176 -0
- zapy/_transport/node/builders/retry.py +156 -0
- zapy/_transport/node/builders/shortcake.py +87 -0
- zapy/_transport/node/builders/tos.py +92 -0
- zapy/_transport/node/builders/usync.py +185 -0
- zapy/_transport/node/helpers.py +201 -0
- zapy/_transport/node/orchestrator.py +210 -0
- zapy/_transport/node/query.py +82 -0
- zapy/_transport/node/transport.py +105 -0
- zapy/_transport/node/usync.py +33 -0
- zapy/_transport/node/xml.py +38 -0
- zapy/_transport/noise/__init__.py +7 -0
- zapy/_transport/noise/cert.py +85 -0
- zapy/_transport/noise/client_payload.py +344 -0
- zapy/_transport/noise/constants.py +12 -0
- zapy/_transport/noise/frame_codec.py +120 -0
- zapy/_transport/noise/handshake.py +92 -0
- zapy/_transport/noise/session.py +493 -0
- zapy/_transport/noise/socket.py +45 -0
- zapy/_transport/noise/types.py +66 -0
- zapy/_transport/noise/version.json +3 -0
- zapy/_transport/proxy.py +35 -0
- zapy/_transport/types.py +19 -0
- zapy/_transport/wa_version_fetcher.py +159 -0
- zapy/_transport/web_socket.py +602 -0
- zapy/_util/__init__.py +3 -0
- zapy/_util/bytes.py +131 -0
- zapy/_util/coercion.py +29 -0
- zapy/_util/collections.py +45 -0
- zapy/_util/primitives.py +49 -0
- zapy/client.py +840 -0
- zapy/errors.py +148 -0
- zapy/events.py +564 -0
- zapy/jid.py +140 -0
- zapy/py.typed +0 -0
- zapy/stores/__init__.py +50 -0
- zapy/stores/base.py +1627 -0
- zapy/stores/json_file.py +359 -0
- zapy/stores/memory.py +322 -0
- zapy/stores/sqlite.py +343 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
"""Business notification parser (``src/client/events/business.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
|
+
|
|
8
|
+
from zapy._proto import WAProto_pb2
|
|
9
|
+
from zapy._protocol.nodes import WA_NODE_TAGS
|
|
10
|
+
from zapy._protocol.notification import WA_NOTIFICATION_TYPES
|
|
11
|
+
from zapy._transport.node.helpers import (
|
|
12
|
+
find_node_child,
|
|
13
|
+
get_node_bytes_content,
|
|
14
|
+
get_node_children,
|
|
15
|
+
get_node_children_by_tag,
|
|
16
|
+
get_node_text_content,
|
|
17
|
+
)
|
|
18
|
+
from zapy._transport.types import BinaryNode
|
|
19
|
+
from zapy._util.primitives import parse_optional_int
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from zapy._client.events.incoming import WaIncomingUnhandledStanzaEvent
|
|
23
|
+
|
|
24
|
+
# Mirrors ``WA_BUSINESS_NOTIFICATION_TAGS`` in ``src/protocol/notification.ts``.
|
|
25
|
+
_BIZ_TAGS = {
|
|
26
|
+
"VERIFIED_NAME": "verified_name",
|
|
27
|
+
"REMOVE": "remove",
|
|
28
|
+
"PROFILE": "profile",
|
|
29
|
+
"PRODUCT_CATALOG": "product_catalog",
|
|
30
|
+
"SUBSCRIPTIONS": "subscriptions",
|
|
31
|
+
"FEATURE_FLAGS": "feature_flags",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_VN_ISSUER_API = "ent:wa"
|
|
35
|
+
_VN_ISSUER_SMB = "smb:wa"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True, slots=True)
|
|
39
|
+
class WaBusinessCategory:
|
|
40
|
+
"""One business category entry."""
|
|
41
|
+
|
|
42
|
+
id: str
|
|
43
|
+
name: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True, slots=True)
|
|
47
|
+
class WaBusinessHoursEntry:
|
|
48
|
+
"""One day's opening-hours config."""
|
|
49
|
+
|
|
50
|
+
day_of_week: str
|
|
51
|
+
mode: str
|
|
52
|
+
open_time: int | None = None
|
|
53
|
+
close_time: int | None = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True, slots=True)
|
|
57
|
+
class WaBusinessHours:
|
|
58
|
+
"""Timezone plus per-day opening-hours config."""
|
|
59
|
+
|
|
60
|
+
timezone: str | None = None
|
|
61
|
+
config: list[WaBusinessHoursEntry] = field(default_factory=list)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True, slots=True)
|
|
65
|
+
class WaBusinessWebsite:
|
|
66
|
+
"""One business website URL."""
|
|
67
|
+
|
|
68
|
+
url: str
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(frozen=True, slots=True)
|
|
72
|
+
class WaBusinessProfileResult:
|
|
73
|
+
"""Decoded ``<profile>`` business payload."""
|
|
74
|
+
|
|
75
|
+
jid: str
|
|
76
|
+
tag: str | None = None
|
|
77
|
+
description: str | None = None
|
|
78
|
+
address: str | None = None
|
|
79
|
+
email: str | None = None
|
|
80
|
+
websites: list[WaBusinessWebsite] | None = None
|
|
81
|
+
categories: list[WaBusinessCategory] | None = None
|
|
82
|
+
business_hours: WaBusinessHours | None = None
|
|
83
|
+
latitude: float | None = None
|
|
84
|
+
longitude: float | None = None
|
|
85
|
+
profile_options: dict[str, str] | None = None
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass(frozen=True, slots=True)
|
|
89
|
+
class WaVerifiedNamePrivacyMode:
|
|
90
|
+
"""Privacy-mode counters attached to a verified-name update."""
|
|
91
|
+
|
|
92
|
+
actual_actors: int
|
|
93
|
+
host_storage: int
|
|
94
|
+
privacy_mode_ts: int
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass(frozen=True, slots=True)
|
|
98
|
+
class WaVerifiedNameResult:
|
|
99
|
+
"""Decoded ``<verified_name>`` payload."""
|
|
100
|
+
|
|
101
|
+
is_api: bool = False
|
|
102
|
+
is_smb: bool = False
|
|
103
|
+
name: str | None = None
|
|
104
|
+
level: str | None = None
|
|
105
|
+
serial: str | None = None
|
|
106
|
+
privacy_mode: WaVerifiedNamePrivacyMode | None = None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True, slots=True)
|
|
110
|
+
class WaBusinessCollectionUpdate:
|
|
111
|
+
"""One product-collection status update."""
|
|
112
|
+
|
|
113
|
+
id: str
|
|
114
|
+
review_status: str | None = None
|
|
115
|
+
reject_reason: str | None = None
|
|
116
|
+
commerce_url: str | None = None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@dataclass(frozen=True, slots=True)
|
|
120
|
+
class WaBusinessSubscription:
|
|
121
|
+
"""One business subscription entry."""
|
|
122
|
+
|
|
123
|
+
id: str
|
|
124
|
+
status: str
|
|
125
|
+
tier: int | None = None
|
|
126
|
+
source: str | None = None
|
|
127
|
+
start_time: int | None = None
|
|
128
|
+
creation_time: int | None = None
|
|
129
|
+
expiration_date: int | None = None
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@dataclass(frozen=True, slots=True)
|
|
133
|
+
class WaBusinessFeatureFlag:
|
|
134
|
+
"""One business feature flag entry."""
|
|
135
|
+
|
|
136
|
+
name: str
|
|
137
|
+
enabled: bool = False
|
|
138
|
+
expiration_time: int | None = None
|
|
139
|
+
limit: int | None = None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclass(frozen=True, slots=True)
|
|
143
|
+
class WaBusinessEvent:
|
|
144
|
+
"""A typed business notification plus the raw stanza."""
|
|
145
|
+
|
|
146
|
+
raw_node: BinaryNode
|
|
147
|
+
stanza_id: str | None
|
|
148
|
+
chat_jid: str | None
|
|
149
|
+
stanza_type: str | None
|
|
150
|
+
offline: bool
|
|
151
|
+
action: str
|
|
152
|
+
timestamp_seconds: int | None = None
|
|
153
|
+
biz_jid: str | None = None
|
|
154
|
+
biz_hash: str | None = None
|
|
155
|
+
verified_name: WaVerifiedNameResult | None = None
|
|
156
|
+
product_ids: list[str] | None = None
|
|
157
|
+
collections: list[WaBusinessCollectionUpdate] | None = None
|
|
158
|
+
subscriptions: list[WaBusinessSubscription] | None = None
|
|
159
|
+
feature_flags: list[WaBusinessFeatureFlag] | None = None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@dataclass(frozen=True, slots=True)
|
|
163
|
+
class WaParseBusinessNotificationResult:
|
|
164
|
+
"""Outcome of ``parse_business_notification_events``."""
|
|
165
|
+
|
|
166
|
+
events: list[WaBusinessEvent]
|
|
167
|
+
unhandled: list[WaIncomingUnhandledStanzaEvent]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _parse_certificate_content(content_bytes: bytes) -> dict[str, Any] | None:
|
|
171
|
+
try:
|
|
172
|
+
cert = WAProto_pb2.VerifiedNameCertificate()
|
|
173
|
+
cert.ParseFromString(content_bytes)
|
|
174
|
+
if not cert.details:
|
|
175
|
+
return None
|
|
176
|
+
details = WAProto_pb2.VerifiedNameCertificate.Details()
|
|
177
|
+
details.ParseFromString(cert.details)
|
|
178
|
+
return {
|
|
179
|
+
"name": details.verifiedName if details.verifiedName else None,
|
|
180
|
+
"serial": str(details.serial),
|
|
181
|
+
"is_api": details.issuer == _VN_ISSUER_API,
|
|
182
|
+
"is_smb": details.issuer == _VN_ISSUER_SMB,
|
|
183
|
+
}
|
|
184
|
+
except Exception:
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def parse_verified_name_node(node: BinaryNode) -> WaVerifiedNameResult | None:
|
|
189
|
+
"""Parse a ``<verified_name>`` child; ``None`` when the tag does not match."""
|
|
190
|
+
if node.tag != _BIZ_TAGS["VERIFIED_NAME"]:
|
|
191
|
+
return None
|
|
192
|
+
content_bytes = get_node_bytes_content(node)
|
|
193
|
+
cert_data = (
|
|
194
|
+
_parse_certificate_content(content_bytes) if content_bytes is not None else None
|
|
195
|
+
)
|
|
196
|
+
privacy_mode: WaVerifiedNamePrivacyMode | None = None
|
|
197
|
+
actual_actors = node.attrs.get("actual_actors")
|
|
198
|
+
host_storage = node.attrs.get("host_storage")
|
|
199
|
+
privacy_mode_ts = node.attrs.get("privacy_mode_ts")
|
|
200
|
+
if (
|
|
201
|
+
actual_actors is not None
|
|
202
|
+
and host_storage is not None
|
|
203
|
+
and privacy_mode_ts is not None
|
|
204
|
+
):
|
|
205
|
+
privacy_mode = WaVerifiedNamePrivacyMode(
|
|
206
|
+
actual_actors=int(actual_actors),
|
|
207
|
+
host_storage=int(host_storage),
|
|
208
|
+
privacy_mode_ts=int(privacy_mode_ts),
|
|
209
|
+
)
|
|
210
|
+
is_api = bool(cert_data and cert_data["is_api"])
|
|
211
|
+
is_smb = bool(cert_data and cert_data["is_smb"])
|
|
212
|
+
name = cert_data["name"] if cert_data else None
|
|
213
|
+
serial: str | None = node.attrs.get("serial")
|
|
214
|
+
if serial is None and cert_data is not None:
|
|
215
|
+
serial = cert_data["serial"]
|
|
216
|
+
return WaVerifiedNameResult(
|
|
217
|
+
name=name,
|
|
218
|
+
level=node.attrs.get("verified_level"),
|
|
219
|
+
serial=serial,
|
|
220
|
+
is_api=is_api,
|
|
221
|
+
is_smb=is_smb,
|
|
222
|
+
privacy_mode=privacy_mode,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _parse_business_categories(node: BinaryNode) -> list[WaBusinessCategory]:
|
|
227
|
+
categories: list[WaBusinessCategory] = []
|
|
228
|
+
for child in get_node_children(node):
|
|
229
|
+
if child.tag != "category":
|
|
230
|
+
continue
|
|
231
|
+
category_id = child.attrs.get("id")
|
|
232
|
+
if not category_id:
|
|
233
|
+
continue
|
|
234
|
+
categories.append(
|
|
235
|
+
WaBusinessCategory(id=category_id, name=get_node_text_content(child) or "")
|
|
236
|
+
)
|
|
237
|
+
return categories
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _parse_business_hours_node(node: BinaryNode) -> WaBusinessHours:
|
|
241
|
+
config: list[WaBusinessHoursEntry] = []
|
|
242
|
+
for child in get_node_children(node):
|
|
243
|
+
if child.tag != "business_hours_config":
|
|
244
|
+
continue
|
|
245
|
+
day_of_week = child.attrs.get("day_of_week")
|
|
246
|
+
mode = child.attrs.get("mode")
|
|
247
|
+
if not day_of_week or not mode:
|
|
248
|
+
continue
|
|
249
|
+
open_time = child.attrs.get("open_time")
|
|
250
|
+
close_time = child.attrs.get("close_time")
|
|
251
|
+
config.append(
|
|
252
|
+
WaBusinessHoursEntry(
|
|
253
|
+
day_of_week=day_of_week,
|
|
254
|
+
mode=mode,
|
|
255
|
+
open_time=int(open_time) if open_time else None,
|
|
256
|
+
close_time=int(close_time) if close_time else None,
|
|
257
|
+
)
|
|
258
|
+
)
|
|
259
|
+
return WaBusinessHours(timezone=node.attrs.get("timezone"), config=config)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _parse_profile_options(node: BinaryNode) -> dict[str, str]:
|
|
263
|
+
options: dict[str, str] = {}
|
|
264
|
+
for child in get_node_children(node):
|
|
265
|
+
text = get_node_text_content(child)
|
|
266
|
+
if text is not None:
|
|
267
|
+
options[child.tag] = text
|
|
268
|
+
return options
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def parse_business_profile_node(node: BinaryNode) -> WaBusinessProfileResult | None:
|
|
272
|
+
"""Parse a ``<profile>`` business child; ``None`` when the tag does not match."""
|
|
273
|
+
if node.tag != _BIZ_TAGS["PROFILE"]:
|
|
274
|
+
return None
|
|
275
|
+
jid = node.attrs.get("jid")
|
|
276
|
+
if not jid:
|
|
277
|
+
return None
|
|
278
|
+
entry = WaBusinessProfileResult(jid=jid, tag=node.attrs.get("tag"))
|
|
279
|
+
children = node.content
|
|
280
|
+
if not isinstance(children, list):
|
|
281
|
+
return entry
|
|
282
|
+
websites: list[WaBusinessWebsite] = []
|
|
283
|
+
description: str | None = None
|
|
284
|
+
address: str | None = None
|
|
285
|
+
email: str | None = None
|
|
286
|
+
categories: list[WaBusinessCategory] | None = None
|
|
287
|
+
business_hours: WaBusinessHours | None = None
|
|
288
|
+
latitude: float | None = None
|
|
289
|
+
longitude: float | None = None
|
|
290
|
+
profile_options: dict[str, str] | None = None
|
|
291
|
+
for child in children:
|
|
292
|
+
text = get_node_text_content(child)
|
|
293
|
+
if child.tag == "description":
|
|
294
|
+
if text is not None:
|
|
295
|
+
description = text
|
|
296
|
+
elif child.tag == "address":
|
|
297
|
+
if text is not None:
|
|
298
|
+
address = text
|
|
299
|
+
elif child.tag == "email":
|
|
300
|
+
if text is not None:
|
|
301
|
+
email = text
|
|
302
|
+
elif child.tag == "website":
|
|
303
|
+
if text is not None:
|
|
304
|
+
websites.append(WaBusinessWebsite(url=text))
|
|
305
|
+
elif child.tag == "latitude":
|
|
306
|
+
if text is not None:
|
|
307
|
+
try:
|
|
308
|
+
value = float(text)
|
|
309
|
+
except ValueError:
|
|
310
|
+
value = float("nan")
|
|
311
|
+
if value == value:
|
|
312
|
+
latitude = value
|
|
313
|
+
elif child.tag == "longitude":
|
|
314
|
+
if text is not None:
|
|
315
|
+
try:
|
|
316
|
+
value = float(text)
|
|
317
|
+
except ValueError:
|
|
318
|
+
value = float("nan")
|
|
319
|
+
if value == value:
|
|
320
|
+
longitude = value
|
|
321
|
+
elif child.tag == "categories":
|
|
322
|
+
categories = _parse_business_categories(child)
|
|
323
|
+
elif child.tag == "business_hours":
|
|
324
|
+
business_hours = _parse_business_hours_node(child)
|
|
325
|
+
elif child.tag == "profile_options":
|
|
326
|
+
profile_options = _parse_profile_options(child)
|
|
327
|
+
return WaBusinessProfileResult(
|
|
328
|
+
jid=jid,
|
|
329
|
+
tag=entry.tag,
|
|
330
|
+
description=description,
|
|
331
|
+
address=address,
|
|
332
|
+
email=email,
|
|
333
|
+
websites=websites or None,
|
|
334
|
+
categories=categories,
|
|
335
|
+
business_hours=business_hours,
|
|
336
|
+
latitude=latitude,
|
|
337
|
+
longitude=longitude,
|
|
338
|
+
profile_options=profile_options,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _parse_subscriptions_list(node: BinaryNode) -> list[WaBusinessSubscription]:
|
|
343
|
+
subs: list[WaBusinessSubscription] = []
|
|
344
|
+
for sub in get_node_children_by_tag(node, "subscription"):
|
|
345
|
+
sub_id = sub.attrs.get("id")
|
|
346
|
+
status = sub.attrs.get("status")
|
|
347
|
+
if not sub_id or not status:
|
|
348
|
+
continue
|
|
349
|
+
subs.append(
|
|
350
|
+
WaBusinessSubscription(
|
|
351
|
+
id=sub_id,
|
|
352
|
+
status=status,
|
|
353
|
+
tier=parse_optional_int(sub.attrs.get("subscription_tier")),
|
|
354
|
+
source=sub.attrs.get("source"),
|
|
355
|
+
start_time=parse_optional_int(sub.attrs.get("subscription_start_time")),
|
|
356
|
+
creation_time=parse_optional_int(
|
|
357
|
+
sub.attrs.get("subscription_creation_time")
|
|
358
|
+
),
|
|
359
|
+
expiration_date=parse_optional_int(
|
|
360
|
+
sub.attrs.get("subscription_end_time")
|
|
361
|
+
),
|
|
362
|
+
)
|
|
363
|
+
)
|
|
364
|
+
return subs
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _parse_feature_flags_list(node: BinaryNode) -> list[WaBusinessFeatureFlag]:
|
|
368
|
+
flags: list[WaBusinessFeatureFlag] = []
|
|
369
|
+
for flag in get_node_children_by_tag(node, "feature_flag"):
|
|
370
|
+
name = flag.attrs.get("name")
|
|
371
|
+
if not name:
|
|
372
|
+
continue
|
|
373
|
+
enabled = (flag.attrs.get("enabled") or "").lower() == "true"
|
|
374
|
+
flags.append(
|
|
375
|
+
WaBusinessFeatureFlag(
|
|
376
|
+
name=name,
|
|
377
|
+
enabled=enabled,
|
|
378
|
+
expiration_time=parse_optional_int(flag.attrs.get("expiration_time")),
|
|
379
|
+
limit=parse_optional_int(flag.attrs.get("limit")),
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
return flags
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _parse_product_ids(catalog_node: BinaryNode) -> list[str]:
|
|
386
|
+
ids: list[str] = []
|
|
387
|
+
for product in get_node_children_by_tag(catalog_node, "product"):
|
|
388
|
+
id_node = find_node_child(product, WA_NODE_TAGS["ID"])
|
|
389
|
+
if id_node is None:
|
|
390
|
+
continue
|
|
391
|
+
text = get_node_text_content(id_node)
|
|
392
|
+
if text:
|
|
393
|
+
ids.append(text)
|
|
394
|
+
return ids
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _parse_collection_updates(
|
|
398
|
+
catalog_node: BinaryNode,
|
|
399
|
+
) -> list[WaBusinessCollectionUpdate]:
|
|
400
|
+
collections: list[WaBusinessCollectionUpdate] = []
|
|
401
|
+
for collection in get_node_children_by_tag(catalog_node, "collection"):
|
|
402
|
+
collection_id = collection.attrs.get("id")
|
|
403
|
+
if not collection_id:
|
|
404
|
+
continue
|
|
405
|
+
review_status: str | None = None
|
|
406
|
+
reject_reason: str | None = None
|
|
407
|
+
commerce_url: str | None = None
|
|
408
|
+
status_info = find_node_child(collection, "status_info")
|
|
409
|
+
if status_info is not None:
|
|
410
|
+
status_node = find_node_child(status_info, WA_NODE_TAGS["STATUS"])
|
|
411
|
+
if status_node is not None:
|
|
412
|
+
text = get_node_text_content(status_node)
|
|
413
|
+
if text:
|
|
414
|
+
review_status = text
|
|
415
|
+
reject_node = find_node_child(status_info, "reject_reason")
|
|
416
|
+
if reject_node is not None:
|
|
417
|
+
text = get_node_text_content(reject_node)
|
|
418
|
+
if text:
|
|
419
|
+
reject_reason = text
|
|
420
|
+
commerce_node = find_node_child(status_info, "commerce_url")
|
|
421
|
+
if commerce_node is not None:
|
|
422
|
+
text = get_node_text_content(commerce_node)
|
|
423
|
+
if text:
|
|
424
|
+
commerce_url = text
|
|
425
|
+
collections.append(
|
|
426
|
+
WaBusinessCollectionUpdate(
|
|
427
|
+
id=collection_id,
|
|
428
|
+
review_status=review_status,
|
|
429
|
+
reject_reason=reject_reason,
|
|
430
|
+
commerce_url=commerce_url,
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
return collections
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _parse_single_business_event(
|
|
437
|
+
notification_node: BinaryNode,
|
|
438
|
+
) -> WaBusinessEvent | None:
|
|
439
|
+
base: dict[str, Any] = {
|
|
440
|
+
"raw_node": notification_node,
|
|
441
|
+
"stanza_id": notification_node.attrs.get("id"),
|
|
442
|
+
"chat_jid": notification_node.attrs.get("from"),
|
|
443
|
+
"stanza_type": notification_node.attrs.get("type"),
|
|
444
|
+
"offline": "offline" in notification_node.attrs,
|
|
445
|
+
"timestamp_seconds": parse_optional_int(notification_node.attrs.get("t")),
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
verified_name = find_node_child(notification_node, _BIZ_TAGS["VERIFIED_NAME"])
|
|
449
|
+
if verified_name is not None:
|
|
450
|
+
vn_jid = verified_name.attrs.get("jid")
|
|
451
|
+
if vn_jid:
|
|
452
|
+
parsed = parse_verified_name_node(verified_name)
|
|
453
|
+
if parsed is None:
|
|
454
|
+
return None
|
|
455
|
+
return WaBusinessEvent(
|
|
456
|
+
action="verified_name_update",
|
|
457
|
+
biz_jid=vn_jid,
|
|
458
|
+
verified_name=parsed,
|
|
459
|
+
**base,
|
|
460
|
+
)
|
|
461
|
+
vn_hash = verified_name.attrs.get("hash")
|
|
462
|
+
if vn_hash:
|
|
463
|
+
return WaBusinessEvent(
|
|
464
|
+
action="verified_name_stale", biz_hash=vn_hash, **base
|
|
465
|
+
)
|
|
466
|
+
return None
|
|
467
|
+
|
|
468
|
+
remove = find_node_child(notification_node, _BIZ_TAGS["REMOVE"])
|
|
469
|
+
if remove is not None:
|
|
470
|
+
rm_jid = remove.attrs.get("jid")
|
|
471
|
+
if rm_jid:
|
|
472
|
+
return WaBusinessEvent(action="business_removed", biz_jid=rm_jid, **base)
|
|
473
|
+
rm_hash = remove.attrs.get("hash")
|
|
474
|
+
if rm_hash:
|
|
475
|
+
return WaBusinessEvent(action="business_removed", biz_hash=rm_hash, **base)
|
|
476
|
+
return None
|
|
477
|
+
|
|
478
|
+
profile = find_node_child(notification_node, _BIZ_TAGS["PROFILE"])
|
|
479
|
+
if profile is not None:
|
|
480
|
+
profile_hash = profile.attrs.get("hash")
|
|
481
|
+
if profile_hash:
|
|
482
|
+
return WaBusinessEvent(
|
|
483
|
+
action="profile_update", biz_hash=profile_hash, **base
|
|
484
|
+
)
|
|
485
|
+
return WaBusinessEvent(
|
|
486
|
+
action="profile_update", biz_jid=notification_node.attrs.get("from"), **base
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
catalog = find_node_child(notification_node, _BIZ_TAGS["PRODUCT_CATALOG"])
|
|
490
|
+
if catalog is not None:
|
|
491
|
+
from_jid = notification_node.attrs.get("from")
|
|
492
|
+
if find_node_child(catalog, "product") is not None:
|
|
493
|
+
return WaBusinessEvent(
|
|
494
|
+
action="product_update",
|
|
495
|
+
biz_jid=from_jid,
|
|
496
|
+
product_ids=_parse_product_ids(catalog),
|
|
497
|
+
**base,
|
|
498
|
+
)
|
|
499
|
+
if find_node_child(catalog, "collection") is not None:
|
|
500
|
+
return WaBusinessEvent(
|
|
501
|
+
action="collection_update",
|
|
502
|
+
biz_jid=from_jid,
|
|
503
|
+
collections=_parse_collection_updates(catalog),
|
|
504
|
+
**base,
|
|
505
|
+
)
|
|
506
|
+
return None
|
|
507
|
+
|
|
508
|
+
subscriptions = find_node_child(notification_node, _BIZ_TAGS["SUBSCRIPTIONS"])
|
|
509
|
+
feature_flags = find_node_child(notification_node, _BIZ_TAGS["FEATURE_FLAGS"])
|
|
510
|
+
if subscriptions is not None or feature_flags is not None:
|
|
511
|
+
return WaBusinessEvent(
|
|
512
|
+
action="subscriptions_update",
|
|
513
|
+
biz_jid=notification_node.attrs.get("from"),
|
|
514
|
+
subscriptions=_parse_subscriptions_list(subscriptions)
|
|
515
|
+
if subscriptions is not None
|
|
516
|
+
else [],
|
|
517
|
+
feature_flags=_parse_feature_flags_list(feature_flags)
|
|
518
|
+
if feature_flags is not None
|
|
519
|
+
else [],
|
|
520
|
+
**base,
|
|
521
|
+
)
|
|
522
|
+
return None
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
def parse_business_notification_events(
|
|
526
|
+
notification_node: BinaryNode,
|
|
527
|
+
) -> WaParseBusinessNotificationResult:
|
|
528
|
+
"""Parse a ``business`` notification into typed events plus unhandled stanzas."""
|
|
529
|
+
from zapy._client.events.incoming import WaIncomingUnhandledStanzaEvent
|
|
530
|
+
|
|
531
|
+
if (
|
|
532
|
+
notification_node.tag != WA_NODE_TAGS["NOTIFICATION"]
|
|
533
|
+
or notification_node.attrs.get("type") != WA_NOTIFICATION_TYPES["BUSINESS"]
|
|
534
|
+
):
|
|
535
|
+
return WaParseBusinessNotificationResult(events=[], unhandled=[])
|
|
536
|
+
|
|
537
|
+
def _unhandled(reason: str) -> WaIncomingUnhandledStanzaEvent:
|
|
538
|
+
return WaIncomingUnhandledStanzaEvent(
|
|
539
|
+
raw_node=notification_node,
|
|
540
|
+
stanza_id=notification_node.attrs.get("id"),
|
|
541
|
+
chat_jid=notification_node.attrs.get("from"),
|
|
542
|
+
stanza_type=notification_node.attrs.get("type"),
|
|
543
|
+
offline="offline" in notification_node.attrs,
|
|
544
|
+
reason=reason,
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
try:
|
|
548
|
+
event = _parse_single_business_event(notification_node)
|
|
549
|
+
if event is not None:
|
|
550
|
+
return WaParseBusinessNotificationResult(events=[event], unhandled=[])
|
|
551
|
+
children = get_node_children(notification_node)
|
|
552
|
+
child_tag = children[0].tag if children else "empty"
|
|
553
|
+
stanza_type = notification_node.attrs.get("type") or "undefined"
|
|
554
|
+
return WaParseBusinessNotificationResult(
|
|
555
|
+
events=[],
|
|
556
|
+
unhandled=[
|
|
557
|
+
_unhandled(f"notification.{stanza_type}.{child_tag}.not_supported")
|
|
558
|
+
],
|
|
559
|
+
)
|
|
560
|
+
except Exception:
|
|
561
|
+
stanza_type = notification_node.attrs.get("type") or "undefined"
|
|
562
|
+
return WaParseBusinessNotificationResult(
|
|
563
|
+
events=[],
|
|
564
|
+
unhandled=[_unhandled(f"notification.{stanza_type}.parse_failed")],
|
|
565
|
+
)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""Call stanza parser (``src/client/events/call.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
from zapy._transport.node.helpers import (
|
|
8
|
+
find_node_child,
|
|
9
|
+
get_first_node_child,
|
|
10
|
+
get_node_children,
|
|
11
|
+
has_node_child,
|
|
12
|
+
)
|
|
13
|
+
from zapy._transport.types import BinaryNode
|
|
14
|
+
from zapy._util.primitives import parse_optional_int
|
|
15
|
+
|
|
16
|
+
# Mirrors ``WA_CALL_PAYLOAD_TAGS`` in ``src/protocol/call.ts``.
|
|
17
|
+
_CALL_PAYLOAD_TAGS = frozenset(
|
|
18
|
+
{
|
|
19
|
+
"offer",
|
|
20
|
+
"offer_notice",
|
|
21
|
+
"accept",
|
|
22
|
+
"preaccept",
|
|
23
|
+
"reject",
|
|
24
|
+
"terminate",
|
|
25
|
+
"transport",
|
|
26
|
+
"mute",
|
|
27
|
+
"video_state",
|
|
28
|
+
"group_info",
|
|
29
|
+
"group_update",
|
|
30
|
+
"enc_rekey",
|
|
31
|
+
"peer_state",
|
|
32
|
+
"flow_control",
|
|
33
|
+
"web_client",
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Payload tags that wa-web answers with a typed ``<receipt>`` child instead of
|
|
38
|
+
# a plain ``<ack class="call"/>``. Source: ``WAWebHandleVoipCall.js``.
|
|
39
|
+
CALL_RECEIPT_PAYLOAD_TAGS = frozenset({"offer", "accept", "reject", "enc_rekey"})
|
|
40
|
+
|
|
41
|
+
# Mirrors ``WA_CALL_NODE_ATTRS`` / ``WA_CALL_CHILD_TAGS`` in ``src/protocol/call.ts``.
|
|
42
|
+
_CALL_ID = "call-id"
|
|
43
|
+
_CALL_CREATOR = "call-creator"
|
|
44
|
+
_GROUP_JID = "group-jid"
|
|
45
|
+
_CALLER_PN = "caller_pn"
|
|
46
|
+
_CALLER_COUNTRY_CODE = "caller_country_code"
|
|
47
|
+
_USERNAME = "username"
|
|
48
|
+
_NOTIFY = "notify"
|
|
49
|
+
_SENDER_LID = "sender_lid"
|
|
50
|
+
_PLATFORM = "platform"
|
|
51
|
+
_VERSION = "version"
|
|
52
|
+
_REASON = "reason"
|
|
53
|
+
_USER_PN = "user_pn"
|
|
54
|
+
_GUEST_NAME = "guest_name"
|
|
55
|
+
_VIDEO = "video"
|
|
56
|
+
_SILENCE = "silence"
|
|
57
|
+
_GROUP_INFO = "group_info"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True, slots=True)
|
|
61
|
+
class WaCallGroupParticipant:
|
|
62
|
+
"""One participant snapshot inside a call ``<group_info>`` block."""
|
|
63
|
+
|
|
64
|
+
jid: str
|
|
65
|
+
user_pn_jid: str | None = None
|
|
66
|
+
username: str | None = None
|
|
67
|
+
guest_name: str | None = None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True, slots=True)
|
|
71
|
+
class ParsedCall:
|
|
72
|
+
"""A ``<call>`` stanza: typed payload discriminator plus caller metadata."""
|
|
73
|
+
|
|
74
|
+
type: str
|
|
75
|
+
is_video: bool = False
|
|
76
|
+
payload_tag: str | None = None
|
|
77
|
+
call_id: str | None = None
|
|
78
|
+
call_creator_jid: str | None = None
|
|
79
|
+
sender_lid_jid: str | None = None
|
|
80
|
+
caller_pn_jid: str | None = None
|
|
81
|
+
group_jid: str | None = None
|
|
82
|
+
caller_username: str | None = None
|
|
83
|
+
caller_country_code: str | None = None
|
|
84
|
+
caller_push_name: str | None = None
|
|
85
|
+
peer_platform: str | None = None
|
|
86
|
+
peer_app_version: str | None = None
|
|
87
|
+
timestamp_seconds: int | None = None
|
|
88
|
+
end_timestamp_seconds: int | None = None
|
|
89
|
+
silence_reason: str | None = None
|
|
90
|
+
group_info: list[WaCallGroupParticipant] | None = field(default=None)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _parse_group_info(node: BinaryNode) -> list[WaCallGroupParticipant] | None:
|
|
94
|
+
children = get_node_children(node)
|
|
95
|
+
if not children:
|
|
96
|
+
return None
|
|
97
|
+
out: list[WaCallGroupParticipant] = []
|
|
98
|
+
for child in children:
|
|
99
|
+
jid = child.attrs.get("jid")
|
|
100
|
+
if not jid:
|
|
101
|
+
continue
|
|
102
|
+
out.append(
|
|
103
|
+
WaCallGroupParticipant(
|
|
104
|
+
jid=jid,
|
|
105
|
+
user_pn_jid=child.attrs.get(_USER_PN),
|
|
106
|
+
username=child.attrs.get(_USERNAME),
|
|
107
|
+
guest_name=child.attrs.get(_GUEST_NAME),
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
return out if out else None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def parse_call_node(node: BinaryNode) -> ParsedCall:
|
|
114
|
+
"""Parse a ``<call>`` stanza into its typed payload plus caller metadata."""
|
|
115
|
+
payload = get_first_node_child(node)
|
|
116
|
+
if payload is None:
|
|
117
|
+
return ParsedCall(type="unknown", is_video=False)
|
|
118
|
+
payload_tag = payload.tag
|
|
119
|
+
call_type = payload_tag if payload_tag in _CALL_PAYLOAD_TAGS else "unknown"
|
|
120
|
+
group_info_node = find_node_child(payload, _GROUP_INFO)
|
|
121
|
+
silence_node = find_node_child(payload, _SILENCE)
|
|
122
|
+
return ParsedCall(
|
|
123
|
+
type=call_type,
|
|
124
|
+
payload_tag=payload_tag,
|
|
125
|
+
call_id=payload.attrs.get(_CALL_ID),
|
|
126
|
+
call_creator_jid=payload.attrs.get(_CALL_CREATOR),
|
|
127
|
+
sender_lid_jid=node.attrs.get(_SENDER_LID),
|
|
128
|
+
caller_pn_jid=payload.attrs.get(_CALLER_PN),
|
|
129
|
+
group_jid=payload.attrs.get(_GROUP_JID),
|
|
130
|
+
is_video=has_node_child(payload, _VIDEO),
|
|
131
|
+
caller_username=payload.attrs.get(_USERNAME),
|
|
132
|
+
caller_country_code=payload.attrs.get(_CALLER_COUNTRY_CODE),
|
|
133
|
+
caller_push_name=payload.attrs.get(_NOTIFY),
|
|
134
|
+
peer_platform=node.attrs.get(_PLATFORM),
|
|
135
|
+
peer_app_version=node.attrs.get(_VERSION),
|
|
136
|
+
timestamp_seconds=parse_optional_int(node.attrs.get("t")),
|
|
137
|
+
end_timestamp_seconds=parse_optional_int(node.attrs.get("e")),
|
|
138
|
+
silence_reason=silence_node.attrs.get(_REASON)
|
|
139
|
+
if silence_node is not None
|
|
140
|
+
else None,
|
|
141
|
+
group_info=_parse_group_info(group_info_node)
|
|
142
|
+
if group_info_node is not None
|
|
143
|
+
else None,
|
|
144
|
+
)
|