wasock 0.5.0b0__tar.gz

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.
wasock-0.5.0b0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ahmed Mohmmed-AM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: wasock
3
+ Version: 0.5.0b0
4
+ Summary: WAsock (WhatsApp Socket) - a Python wrapper around Baileys for building WhatsApp bots
5
+ Author: Ahmed Mohmmed-AM
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Ahmed-Mohmmed-AM/WAsock
8
+ Project-URL: Repository, https://github.com/Ahmed-Mohmmed-AM/WAsock
9
+ Keywords: whatsapp,baileys,bot,chat,automation,whatsapp-sockt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: qrcode
18
+ Requires-Dist: pillow
19
+ Dynamic: license-file
20
+
21
+ # WAsock
22
+
23
+ **wasock** (WhatsApp Socket) — مكتبة بايثون بسيطة للتعامل مع واتساب، مبنية فوق [Baileys](https://github.com/WhiskeySockets/Baileys) عن طريق عملية Node.js فرعية بتتواصل مع بايثون عبر TCP socket.
24
+
25
+ صُنعت بواسطة مطور مصري 🇪🇬 — Ahmed Mohmmed-AM.
26
+
27
+ > **الحالة:** `0.5.0-Beta` — لسه تحت التطوير، ممكن يحصل تغييرات في الـ API قبل النسخة المستقرة.
28
+
29
+ ---
30
+
31
+ ## نظرة عامة (Overview)
32
+
33
+ wasock بتديك واجهة بايثونية سهلة للتعامل مع واتساب: استقبال رسايل، الرد عليها، بعت رسايل جديدة، حذف رسايل، وعرض QR Code لتسجيل الدخول — من غير ما تحتاج تكتب سطر JavaScript واحد.
34
+
35
+ wasock is a lightweight Python wrapper around [Baileys](https://github.com/WhiskeySockets/Baileys). It spawns a Node.js subprocess and talks to it over a local TCP socket, so you can send, receive, reply to, and delete WhatsApp messages entirely from Python.
36
+
37
+ ---
38
+
39
+ ## المتطلبات (Requirements)
40
+
41
+ - Python >= 3.8
42
+ - Node.js (>= 18 موصى بيه)
43
+ - اتصال بالإنترنت لتثبيت اعتماديات npm الأولى
44
+
45
+ ---
46
+
47
+ ## التثبيت (Installation)
48
+
49
+ ```bash
50
+ pip install wasock
51
+ ```
52
+
53
+ بعد التثبيت، لازم تثبت اعتماديات Node مرة واحدة (Baileys وpino) جوه فولدر المكتبة:
54
+
55
+ After installing, you need to install the Node.js dependencies once:
56
+
57
+ ```bash
58
+ cd $(python -c "import wasock, os; print(os.path.join(os.path.dirname(wasock.__file__), 'node'))")
59
+ npm install
60
+ ```
61
+
62
+ ---
63
+
64
+ ## استخدام سريع (Quick Start)
65
+
66
+ ```python
67
+ from wasock import WhatsAppSocket, Message, QRCode, Connection
68
+
69
+ bot = WhatsAppSocket(authName="auth", loggerLevel="silent")
70
+
71
+ def onQr(data):
72
+ qr = QRCode(data["qr"], size="mid", type="img")
73
+ img = qr.render()
74
+ img.save("qr.png")
75
+ print("امسح qr.png من واتساب على موبايلك")
76
+
77
+ def onConnection(data):
78
+ conn = Connection(data)
79
+ if conn.connected:
80
+ print("الاتصال فتح!")
81
+ else:
82
+ print(f"الاتصال اتقفل: {conn.reason}")
83
+
84
+ def onMessage(data):
85
+ message = Message(data, bot.nodeJS)
86
+ if message.fromBot:
87
+ return
88
+
89
+ if message.text == "!ping":
90
+ message.reply("pong")
91
+
92
+ bot.on("qr", onQr)
93
+ bot.on("connection", onConnection)
94
+ bot.on("message", onMessage)
95
+
96
+ bot.start()
97
+
98
+ try:
99
+ input("البوت شغال، دوس Enter للخروج...\n")
100
+ finally:
101
+ bot.end()
102
+ ```
103
+
104
+ ---
105
+
106
+ ## الـ API
107
+
108
+ ### `WhatsAppSocket(authName="auth", loggerLevel="silent")`
109
+
110
+ بيبدأ الاتصال بسيرفر Node ويجهز الجلسة.
111
+
112
+ - `.start()` — يبدأ الاتصال الفعلي بواتساب.
113
+ - `.on(event, callback)` — يسجل event listener (`"qr"`, `"connection"`, `"message"`).
114
+ - `.end()` — يقفل الاتصال ويوقف عملية Node.
115
+
116
+ ### `Message`
117
+
118
+ بيتبني تلقائيًا لكل رسالة واردة. من أهم الخصائص:
119
+
120
+
121
+ | الخاصية | الوصف |
122
+ | ------------------------------------------- | ------------------------------------------------------------------------------- |
123
+ | `.text` | نص الرسالة |
124
+ | `.chat` | الـ JID بتاع المحادثة |
125
+ | `.fromBot` | `True` لو الرسالة من البوت نفسه |
126
+ | `.quoted` / `.quotedText` / `.quotedSender` | بيانات الرسالة المقتبسة (لو الرسالة ريبلاي) |
127
+
128
+ **Methods:**
129
+
130
+ - `.reply(msg, chat=None, quoted=None)` — يرد على الرسالة.
131
+ - `.send(msg, chat=None)` — يبعت رسالة جديدة (من غير quote).
132
+ - `.delete()` — يمسح الرسالة (Delete for Everyone).
133
+
134
+ ### `QRCode(data, size="mid", type="terminal")`
135
+
136
+ - `size`: `"small"`, `"mid"`, `"big"`
137
+ - `type`: `"terminal"` (يطبع في التيرمينال) أو `"img"` (يرجع صورة تقدر تعمله `.save()`)
138
+
139
+ ### `Connection`
140
+
141
+ - `.connected` — `True`/`False`
142
+ - `.statusCode` — كود الإغلاق (لو موجود)
143
+ - `.reason` — سبب الإغلاق (لو موجود)
144
+ - `.isAuthFailure()` — `True` لو السبب كان 401 (محتاج QR جديد)
145
+
146
+ ---
147
+
148
+ ## ملاحظات مهمة (Important Notes)
149
+
150
+ - فولدر `auth/` بيحتوي على بيانات جلسة واتساب الحساسة — **متعملوش commit على GitHub أبدًا**.
151
+ - مكان `auth/` بيتحدد نسبيًا لمكان تشغيل السكريبت (working directory)، مش لمكان المكتبة.
152
+
153
+ ---
154
+
155
+ ## الترخيص (License)
156
+
157
+ MIT License — تفاصيل أكتر في ملف [LICENSE](./LICENSE).
158
+
159
+ ---
160
+
161
+ ## المطور (Author)
162
+
163
+ Ahmed Mohmmed-AM — مطور مصري 🇪🇬
164
+ GitHub: [@Ahmed-Mohmmed-AM](https://github.com/Ahmed-Mohmmed-AM)
@@ -0,0 +1,144 @@
1
+ # WAsock
2
+
3
+ **wasock** (WhatsApp Socket) — مكتبة بايثون بسيطة للتعامل مع واتساب، مبنية فوق [Baileys](https://github.com/WhiskeySockets/Baileys) عن طريق عملية Node.js فرعية بتتواصل مع بايثون عبر TCP socket.
4
+
5
+ صُنعت بواسطة مطور مصري 🇪🇬 — Ahmed Mohmmed-AM.
6
+
7
+ > **الحالة:** `0.5.0-Beta` — لسه تحت التطوير، ممكن يحصل تغييرات في الـ API قبل النسخة المستقرة.
8
+
9
+ ---
10
+
11
+ ## نظرة عامة (Overview)
12
+
13
+ wasock بتديك واجهة بايثونية سهلة للتعامل مع واتساب: استقبال رسايل، الرد عليها، بعت رسايل جديدة، حذف رسايل، وعرض QR Code لتسجيل الدخول — من غير ما تحتاج تكتب سطر JavaScript واحد.
14
+
15
+ wasock is a lightweight Python wrapper around [Baileys](https://github.com/WhiskeySockets/Baileys). It spawns a Node.js subprocess and talks to it over a local TCP socket, so you can send, receive, reply to, and delete WhatsApp messages entirely from Python.
16
+
17
+ ---
18
+
19
+ ## المتطلبات (Requirements)
20
+
21
+ - Python >= 3.8
22
+ - Node.js (>= 18 موصى بيه)
23
+ - اتصال بالإنترنت لتثبيت اعتماديات npm الأولى
24
+
25
+ ---
26
+
27
+ ## التثبيت (Installation)
28
+
29
+ ```bash
30
+ pip install wasock
31
+ ```
32
+
33
+ بعد التثبيت، لازم تثبت اعتماديات Node مرة واحدة (Baileys وpino) جوه فولدر المكتبة:
34
+
35
+ After installing, you need to install the Node.js dependencies once:
36
+
37
+ ```bash
38
+ cd $(python -c "import wasock, os; print(os.path.join(os.path.dirname(wasock.__file__), 'node'))")
39
+ npm install
40
+ ```
41
+
42
+ ---
43
+
44
+ ## استخدام سريع (Quick Start)
45
+
46
+ ```python
47
+ from wasock import WhatsAppSocket, Message, QRCode, Connection
48
+
49
+ bot = WhatsAppSocket(authName="auth", loggerLevel="silent")
50
+
51
+ def onQr(data):
52
+ qr = QRCode(data["qr"], size="mid", type="img")
53
+ img = qr.render()
54
+ img.save("qr.png")
55
+ print("امسح qr.png من واتساب على موبايلك")
56
+
57
+ def onConnection(data):
58
+ conn = Connection(data)
59
+ if conn.connected:
60
+ print("الاتصال فتح!")
61
+ else:
62
+ print(f"الاتصال اتقفل: {conn.reason}")
63
+
64
+ def onMessage(data):
65
+ message = Message(data, bot.nodeJS)
66
+ if message.fromBot:
67
+ return
68
+
69
+ if message.text == "!ping":
70
+ message.reply("pong")
71
+
72
+ bot.on("qr", onQr)
73
+ bot.on("connection", onConnection)
74
+ bot.on("message", onMessage)
75
+
76
+ bot.start()
77
+
78
+ try:
79
+ input("البوت شغال، دوس Enter للخروج...\n")
80
+ finally:
81
+ bot.end()
82
+ ```
83
+
84
+ ---
85
+
86
+ ## الـ API
87
+
88
+ ### `WhatsAppSocket(authName="auth", loggerLevel="silent")`
89
+
90
+ بيبدأ الاتصال بسيرفر Node ويجهز الجلسة.
91
+
92
+ - `.start()` — يبدأ الاتصال الفعلي بواتساب.
93
+ - `.on(event, callback)` — يسجل event listener (`"qr"`, `"connection"`, `"message"`).
94
+ - `.end()` — يقفل الاتصال ويوقف عملية Node.
95
+
96
+ ### `Message`
97
+
98
+ بيتبني تلقائيًا لكل رسالة واردة. من أهم الخصائص:
99
+
100
+
101
+ | الخاصية | الوصف |
102
+ | ------------------------------------------- | ------------------------------------------------------------------------------- |
103
+ | `.text` | نص الرسالة |
104
+ | `.chat` | الـ JID بتاع المحادثة |
105
+ | `.fromBot` | `True` لو الرسالة من البوت نفسه |
106
+ | `.quoted` / `.quotedText` / `.quotedSender` | بيانات الرسالة المقتبسة (لو الرسالة ريبلاي) |
107
+
108
+ **Methods:**
109
+
110
+ - `.reply(msg, chat=None, quoted=None)` — يرد على الرسالة.
111
+ - `.send(msg, chat=None)` — يبعت رسالة جديدة (من غير quote).
112
+ - `.delete()` — يمسح الرسالة (Delete for Everyone).
113
+
114
+ ### `QRCode(data, size="mid", type="terminal")`
115
+
116
+ - `size`: `"small"`, `"mid"`, `"big"`
117
+ - `type`: `"terminal"` (يطبع في التيرمينال) أو `"img"` (يرجع صورة تقدر تعمله `.save()`)
118
+
119
+ ### `Connection`
120
+
121
+ - `.connected` — `True`/`False`
122
+ - `.statusCode` — كود الإغلاق (لو موجود)
123
+ - `.reason` — سبب الإغلاق (لو موجود)
124
+ - `.isAuthFailure()` — `True` لو السبب كان 401 (محتاج QR جديد)
125
+
126
+ ---
127
+
128
+ ## ملاحظات مهمة (Important Notes)
129
+
130
+ - فولدر `auth/` بيحتوي على بيانات جلسة واتساب الحساسة — **متعملوش commit على GitHub أبدًا**.
131
+ - مكان `auth/` بيتحدد نسبيًا لمكان تشغيل السكريبت (working directory)، مش لمكان المكتبة.
132
+
133
+ ---
134
+
135
+ ## الترخيص (License)
136
+
137
+ MIT License — تفاصيل أكتر في ملف [LICENSE](./LICENSE).
138
+
139
+ ---
140
+
141
+ ## المطور (Author)
142
+
143
+ Ahmed Mohmmed-AM — مطور مصري 🇪🇬
144
+ GitHub: [@Ahmed-Mohmmed-AM](https://github.com/Ahmed-Mohmmed-AM)
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "wasock"
7
+ version = "0.5.0b0"
8
+ description = "WAsock (WhatsApp Socket) - a Python wrapper around Baileys for building WhatsApp bots"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "Ahmed Mohmmed-AM" }
14
+ ]
15
+ keywords = ["whatsapp", "baileys", "bot", "chat", "automation", "whatsapp-sockt"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ ]
22
+ dependencies = [
23
+ "qrcode",
24
+ "pillow"
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/Ahmed-Mohmmed-AM/WAsock"
29
+ Repository = "https://github.com/Ahmed-Mohmmed-AM/WAsock"
30
+
31
+ [tool.setuptools.packages.find]
32
+ include = ["wasock*"]
33
+
34
+ [tool.setuptools.package-data]
35
+ wapyt = ["node/**/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from .whatsappsocket import WhatsAppSocket
2
+ from .qrcode import QRCode
3
+ from .connection import Connection
4
+ from .message import Message
5
+
6
+ __version__ = "Wapyt @0.5.0-Beta"
@@ -0,0 +1,8 @@
1
+ class Connection:
2
+ def __init__(self, connection):
3
+ self.connected = True if connection["status"] == "open" else False
4
+ self.statusCode = connection.get("statusCode", None)
5
+ self.reason = connection.get("reason", None)
6
+
7
+ def isAuthFailure(self):
8
+ return self.statusCode == 401
@@ -0,0 +1,72 @@
1
+ class Message:
2
+ def __init__(self, data, nodeJS):
3
+ message = data["message"]["messages"][0]
4
+
5
+ self.data = message
6
+ self.nodeJS = nodeJS
7
+
8
+ self.id = message["key"]["id"]
9
+ self.chat = message["key"]["remoteJid"]
10
+ self.sender = message["key"].get("remoteJidAlt")
11
+ self.fromBot = message["key"]["fromMe"]
12
+ self.timestamp = message["messageTimestamp"]
13
+ self.name = message.get("pushName")
14
+
15
+ content = message.get("message", {})
16
+
17
+ self.text = (
18
+ content.get("conversation")
19
+ or content.get("extendedTextMessage", {}).get("text")
20
+ )
21
+
22
+ self.quoted = None
23
+ self.quotedText = None
24
+ self.quotedId = None
25
+ self.quotedSender = None
26
+
27
+ contextInfo = content.get("extendedTextMessage", {}).get("contextInfo")
28
+
29
+ if contextInfo and contextInfo.get("quotedMessage"):
30
+ self.quoted = contextInfo["quotedMessage"]
31
+ self.quotedId = contextInfo.get("stanzaId")
32
+ self.quotedSender = contextInfo.get("participant")
33
+
34
+ self.quotedText = (
35
+ self.quoted.get("conversation")
36
+ or self.quoted.get("extendedTextMessage", {}).get("text")
37
+ )
38
+
39
+ def reply(self, msg, chat=None, quoted=None):
40
+ if chat is None: chat = self.chat
41
+ if quoted is None: quoted = self.data
42
+
43
+ if msg is None: msg = ""
44
+
45
+ self.nodeJS.send({
46
+ "action": "replyMessage",
47
+ "chat": chat,
48
+ "msg": msg,
49
+ "quoted": quoted
50
+ })
51
+
52
+ def send(self, msg, chat=None):
53
+ if chat is None: chat = self.chat
54
+
55
+ if msg is None: msg = ""
56
+
57
+ self.nodeJS.send({
58
+ "action": "sendMessage",
59
+ "chat": chat,
60
+ "msg": msg,
61
+ })
62
+
63
+ def delete(self):
64
+ self.nodeJS.send({
65
+ "action": "deleteMessage",
66
+ "chat": self.chat,
67
+ "key": self.getKey()
68
+ })
69
+
70
+ def getKey(self):
71
+ key = self.data["key"]
72
+ return key
@@ -0,0 +1,78 @@
1
+ import subprocess, atexit, socket, queue, threading, json, time, os
2
+ from concurrent.futures import ThreadPoolExecutor
3
+
4
+ def connectToServer(self):
5
+ for _ in range(50):
6
+ try:
7
+ self.sock.connect(("127.0.0.1", 5000))
8
+ return
9
+ except ConnectionRefusedError:
10
+ time.sleep(0.1)
11
+
12
+ raise ConnectionError("Could not connect to Node.js server")
13
+
14
+ _SERVER_JS_PATH = os.path.join(os.path.dirname(__file__), "node", "server.js")
15
+
16
+ class NodeJS:
17
+ def __init__(self):
18
+ self.process = subprocess.Popen(
19
+ ["node", _SERVER_JS_PATH]
20
+ )
21
+
22
+ atexit.register(self.end)
23
+
24
+ self.sock = socket.socket()
25
+ connectToServer(self)
26
+
27
+ self.responses = queue.Queue()
28
+
29
+ self.events = {}
30
+
31
+ self.executor = ThreadPoolExecutor(max_workers=10)
32
+
33
+ self.threading = threading.Thread(
34
+ target=self.receive,
35
+ daemon=True
36
+ )
37
+ self.threading.start()
38
+
39
+ def receive(self):
40
+ buffer = ""
41
+
42
+ while True:
43
+ data = self.sock.recv(4096)
44
+
45
+ if not data:
46
+ break
47
+
48
+ buffer += data.decode("utf-8")
49
+
50
+ while "\n" in buffer:
51
+ line, buffer = buffer.split("\n", 1)
52
+
53
+ if not line:
54
+ continue
55
+
56
+ message = json.loads(line)
57
+
58
+ if message.get("type") == "event":
59
+ event = message.get("event")
60
+ callback = self.events.get(event)
61
+
62
+ if callback:
63
+ self.executor.submit(callback, message)
64
+ else:
65
+ self.responses.put(message)
66
+
67
+ def on(self, event, callback):
68
+ self.events[event] = callback
69
+
70
+ def send(self, message):
71
+ data = json.dumps(message).encode("utf-8") + b"\n"
72
+ self.sock.sendall(data)
73
+ return self.responses.get()
74
+
75
+ def end(self):
76
+ self.sock.close()
77
+ self.process.terminate()
78
+ self.process.wait()
@@ -0,0 +1,25 @@
1
+ import qrcode
2
+
3
+ class QRCode:
4
+ def __init__(self, data, size="mid", type="terminal"):
5
+ sizes = {
6
+ "small": 6,
7
+ "mid" : 10,
8
+ "big": 16
9
+ }
10
+
11
+ boxSize = sizes.get(size.lower(), 10)
12
+
13
+ self.qr = qrcode.QRCode(version=None, box_size=boxSize, border=4)
14
+ self.qr.add_data(data)
15
+ self.qr.make(fit=True)
16
+ self.type = type.lower()
17
+
18
+ def render(self):
19
+ if self.type == "img":
20
+ return self.qr.make_image(fill_color="black", back_color="white")
21
+ elif self.type == "terminal":
22
+ self.qr.print_ascii(invert=True)
23
+ return None
24
+ else:
25
+ raise ValueError(f"Unknown type: {self.type}")
@@ -0,0 +1,24 @@
1
+ from .nodejs import NodeJS
2
+
3
+ class WhatsAppSocket:
4
+ def __init__(self, authName="auth", loggerLevel="silent"):
5
+ if not loggerLevel.lower() in ["debug", "error", "fatal", "info", "silent", "trace", "warn"]:
6
+ raise SyntaxError(f"Unknown logger type {loggerLevel}")
7
+ if not isinstance(authName, str):
8
+ raise TypeError("authName must be string")
9
+
10
+ self.nodeJS = NodeJS()
11
+
12
+ response = self.nodeJS.send({"action": "setup", "loggerLevel": loggerLevel.lower(), "authName": authName})
13
+
14
+ if not response["success"]:
15
+ raise RuntimeError(response.get("message", "Setup failed"))
16
+
17
+ def start(self):
18
+ return self.nodeJS.send({"action": "start"})
19
+
20
+ def on(self, event, callback):
21
+ self.nodeJS.on(event, callback)
22
+
23
+ def end(self):
24
+ self.nodeJS.end()
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: wasock
3
+ Version: 0.5.0b0
4
+ Summary: WAsock (WhatsApp Socket) - a Python wrapper around Baileys for building WhatsApp bots
5
+ Author: Ahmed Mohmmed-AM
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Ahmed-Mohmmed-AM/WAsock
8
+ Project-URL: Repository, https://github.com/Ahmed-Mohmmed-AM/WAsock
9
+ Keywords: whatsapp,baileys,bot,chat,automation,whatsapp-sockt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: qrcode
18
+ Requires-Dist: pillow
19
+ Dynamic: license-file
20
+
21
+ # WAsock
22
+
23
+ **wasock** (WhatsApp Socket) — مكتبة بايثون بسيطة للتعامل مع واتساب، مبنية فوق [Baileys](https://github.com/WhiskeySockets/Baileys) عن طريق عملية Node.js فرعية بتتواصل مع بايثون عبر TCP socket.
24
+
25
+ صُنعت بواسطة مطور مصري 🇪🇬 — Ahmed Mohmmed-AM.
26
+
27
+ > **الحالة:** `0.5.0-Beta` — لسه تحت التطوير، ممكن يحصل تغييرات في الـ API قبل النسخة المستقرة.
28
+
29
+ ---
30
+
31
+ ## نظرة عامة (Overview)
32
+
33
+ wasock بتديك واجهة بايثونية سهلة للتعامل مع واتساب: استقبال رسايل، الرد عليها، بعت رسايل جديدة، حذف رسايل، وعرض QR Code لتسجيل الدخول — من غير ما تحتاج تكتب سطر JavaScript واحد.
34
+
35
+ wasock is a lightweight Python wrapper around [Baileys](https://github.com/WhiskeySockets/Baileys). It spawns a Node.js subprocess and talks to it over a local TCP socket, so you can send, receive, reply to, and delete WhatsApp messages entirely from Python.
36
+
37
+ ---
38
+
39
+ ## المتطلبات (Requirements)
40
+
41
+ - Python >= 3.8
42
+ - Node.js (>= 18 موصى بيه)
43
+ - اتصال بالإنترنت لتثبيت اعتماديات npm الأولى
44
+
45
+ ---
46
+
47
+ ## التثبيت (Installation)
48
+
49
+ ```bash
50
+ pip install wasock
51
+ ```
52
+
53
+ بعد التثبيت، لازم تثبت اعتماديات Node مرة واحدة (Baileys وpino) جوه فولدر المكتبة:
54
+
55
+ After installing, you need to install the Node.js dependencies once:
56
+
57
+ ```bash
58
+ cd $(python -c "import wasock, os; print(os.path.join(os.path.dirname(wasock.__file__), 'node'))")
59
+ npm install
60
+ ```
61
+
62
+ ---
63
+
64
+ ## استخدام سريع (Quick Start)
65
+
66
+ ```python
67
+ from wasock import WhatsAppSocket, Message, QRCode, Connection
68
+
69
+ bot = WhatsAppSocket(authName="auth", loggerLevel="silent")
70
+
71
+ def onQr(data):
72
+ qr = QRCode(data["qr"], size="mid", type="img")
73
+ img = qr.render()
74
+ img.save("qr.png")
75
+ print("امسح qr.png من واتساب على موبايلك")
76
+
77
+ def onConnection(data):
78
+ conn = Connection(data)
79
+ if conn.connected:
80
+ print("الاتصال فتح!")
81
+ else:
82
+ print(f"الاتصال اتقفل: {conn.reason}")
83
+
84
+ def onMessage(data):
85
+ message = Message(data, bot.nodeJS)
86
+ if message.fromBot:
87
+ return
88
+
89
+ if message.text == "!ping":
90
+ message.reply("pong")
91
+
92
+ bot.on("qr", onQr)
93
+ bot.on("connection", onConnection)
94
+ bot.on("message", onMessage)
95
+
96
+ bot.start()
97
+
98
+ try:
99
+ input("البوت شغال، دوس Enter للخروج...\n")
100
+ finally:
101
+ bot.end()
102
+ ```
103
+
104
+ ---
105
+
106
+ ## الـ API
107
+
108
+ ### `WhatsAppSocket(authName="auth", loggerLevel="silent")`
109
+
110
+ بيبدأ الاتصال بسيرفر Node ويجهز الجلسة.
111
+
112
+ - `.start()` — يبدأ الاتصال الفعلي بواتساب.
113
+ - `.on(event, callback)` — يسجل event listener (`"qr"`, `"connection"`, `"message"`).
114
+ - `.end()` — يقفل الاتصال ويوقف عملية Node.
115
+
116
+ ### `Message`
117
+
118
+ بيتبني تلقائيًا لكل رسالة واردة. من أهم الخصائص:
119
+
120
+
121
+ | الخاصية | الوصف |
122
+ | ------------------------------------------- | ------------------------------------------------------------------------------- |
123
+ | `.text` | نص الرسالة |
124
+ | `.chat` | الـ JID بتاع المحادثة |
125
+ | `.fromBot` | `True` لو الرسالة من البوت نفسه |
126
+ | `.quoted` / `.quotedText` / `.quotedSender` | بيانات الرسالة المقتبسة (لو الرسالة ريبلاي) |
127
+
128
+ **Methods:**
129
+
130
+ - `.reply(msg, chat=None, quoted=None)` — يرد على الرسالة.
131
+ - `.send(msg, chat=None)` — يبعت رسالة جديدة (من غير quote).
132
+ - `.delete()` — يمسح الرسالة (Delete for Everyone).
133
+
134
+ ### `QRCode(data, size="mid", type="terminal")`
135
+
136
+ - `size`: `"small"`, `"mid"`, `"big"`
137
+ - `type`: `"terminal"` (يطبع في التيرمينال) أو `"img"` (يرجع صورة تقدر تعمله `.save()`)
138
+
139
+ ### `Connection`
140
+
141
+ - `.connected` — `True`/`False`
142
+ - `.statusCode` — كود الإغلاق (لو موجود)
143
+ - `.reason` — سبب الإغلاق (لو موجود)
144
+ - `.isAuthFailure()` — `True` لو السبب كان 401 (محتاج QR جديد)
145
+
146
+ ---
147
+
148
+ ## ملاحظات مهمة (Important Notes)
149
+
150
+ - فولدر `auth/` بيحتوي على بيانات جلسة واتساب الحساسة — **متعملوش commit على GitHub أبدًا**.
151
+ - مكان `auth/` بيتحدد نسبيًا لمكان تشغيل السكريبت (working directory)، مش لمكان المكتبة.
152
+
153
+ ---
154
+
155
+ ## الترخيص (License)
156
+
157
+ MIT License — تفاصيل أكتر في ملف [LICENSE](./LICENSE).
158
+
159
+ ---
160
+
161
+ ## المطور (Author)
162
+
163
+ Ahmed Mohmmed-AM — مطور مصري 🇪🇬
164
+ GitHub: [@Ahmed-Mohmmed-AM](https://github.com/Ahmed-Mohmmed-AM)
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ wasock/__init__.py
5
+ wasock/connection.py
6
+ wasock/message.py
7
+ wasock/nodejs.py
8
+ wasock/qrcode.py
9
+ wasock/whatsappsocket.py
10
+ wasock.egg-info/PKG-INFO
11
+ wasock.egg-info/SOURCES.txt
12
+ wasock.egg-info/dependency_links.txt
13
+ wasock.egg-info/requires.txt
14
+ wasock.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ qrcode
2
+ pillow
@@ -0,0 +1 @@
1
+ wasock