Skip to content

Commit 3e04813

Browse files
committed
fix: new arguments
1 parent 66dd511 commit 3e04813

File tree

47 files changed

+2031
-929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2031
-929
lines changed

docs/getstarted.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Getting Started with Neonize
2+
===========================
3+
4+
What is Neonize?
5+
--------------
6+
7+
Neonize is a Python library that provides an asynchronous client interface for WhatsApp messaging. It allows developers to build applications that can programmatically send and receive WhatsApp messages, handle various media types, and interact with WhatsApp features.
8+
9+
Installation
10+
-----------
11+
12+
You can install Neonize using pip:
13+
14+
.. code-block:: bash
15+
16+
pip install neonize
17+
18+
For the development version, you can install directly from GitHub:
19+
20+
.. code-block:: bash
21+
22+
pip install git+https://github.com/krypton-byte/neonize.git
23+
24+
Requirements
25+
~~~~~~~~~~~
26+
27+
- Python 3.10 or higher
28+
- Async/await support
29+
30+
Basic Usage
31+
----------
32+
33+
Here's a simple example of how to use Neonize:
34+
35+
.. code-block:: python
36+
37+
import asyncio
38+
from neonize import NewAClient
39+
from neonize.events import MessageEv
40+
41+
async def handler(client: NewAClient, message: MessageEv):
42+
# Get the chat and text from the message
43+
chat = message.Info.MessageSource.Chat
44+
text = message.Message.conversation
45+
46+
# Simple ping-pong example
47+
if text == "ping":
48+
await client.send_message(chat, "pong!")
49+
50+
async def main():
51+
# Initialize the client
52+
client = NewAClient()
53+
54+
# Register the message handler
55+
client.register_callback(handler)
56+
57+
# Connect and start listening
58+
await client.connect()
59+
60+
# Keep the client running
61+
while client.connected:
62+
await asyncio.sleep(1)
63+
64+
if __name__ == "__main__":
65+
asyncio.run(main())
66+
67+
Features
68+
--------
69+
70+
Neonize supports many WhatsApp features, including:
71+
72+
* Sending and receiving text messages
73+
* Handling media (images, videos, audio, documents)
74+
* Creating and interacting with polls
75+
* Building and sending stickers
76+
* Message editing
77+
* Interactive buttons and lists
78+
* Chat settings management (muting, pinning, archiving)
79+
* And much more!
80+
81+
For more detailed documentation and examples, please check the API reference and examples sections.

docs/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@ Welcome to neonize's documentation!
99
.. toctree::
1010
:maxdepth: 2
1111
:caption: Contents:
12+
13+
getstarted
14+
15+
.. toctree::
16+
:maxdepth: 2
17+
:caption: API Reference:
18+
1219
source/modules
1320

21+
.. toctree::
22+
:maxdepth: 1
23+
:caption: Development:
24+
25+
GitHub Repository <https://github.com/krypton-byte/neonize>
26+
Issue Tracker <https://github.com/krypton-byte/neonize/issues>
27+
1428

1529
Indices and tables
1630
==================

examples/async_basic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from neonize.types import MessageServerID
2323
from neonize.utils import log
24-
from neonize.utils.enum import ReceiptType
24+
from neonize.utils.enum import ReceiptType, VoteType
2525

2626
sys.path.insert(0, os.getcwd())
2727

@@ -230,6 +230,14 @@ async def handler(client: NewAClient, message: MessageEv):
230230
await client.send_message(
231231
chat, (await client.chat_settings.get_chat_settings(chat)).__str__()
232232
)
233+
case "poll_vote":
234+
await client.send_message(chat, await client.build_poll_vote_creation(
235+
"Food",
236+
["Pizza", "Burger", "Sushi"],
237+
VoteType.SINGLE,
238+
))
239+
case "send_react":
240+
await client.send_message(chat, await client.build_reaction(chat, message.Info.MessageSource.Sender, message.Info.ID, reaction="🗿"))
233241
case "edit_message":
234242
text = "Hello World"
235243
id_msg = None

examples/basic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from neonize.types import MessageServerID
2323
from neonize.utils import log, build_jid
24-
from neonize.utils.enum import ReceiptType
24+
from neonize.utils.enum import ReceiptType, VoteType
2525

2626
sys.path.insert(0, os.getcwd())
2727

@@ -226,6 +226,14 @@ def handler(client: NewClient, message: MessageEv):
226226
client.chat_settings.put_archived(chat, False)
227227
case "get_chat_settings":
228228
client.send_message(chat, client.chat_settings.get_chat_settings(chat).__str__())
229+
case "poll_vote":
230+
client.send_message(chat, client.build_poll_vote_creation(
231+
"Food",
232+
["Pizza", "Burger", "Sushi"],
233+
VoteType.SINGLE,
234+
))
235+
case "send_react":
236+
client.send_message(chat, client.build_reaction(chat, message.Info.MessageSource.Sender, message.Info.ID, reaction="🗿"))
229237
case "edit_message":
230238
text = "Hello World"
231239
id_msg = None

goneonize/chat_settings_store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/krypton-byte/neonize/utils"
1515
)
1616
import (
17+
"context"
1718
"time"
1819

1920
"google.golang.org/protobuf/proto"
@@ -23,7 +24,7 @@ import (
2324
func PutMutedUntil(id *C.char, user *C.uchar, userSize C.int, mutedUntil C.float) *C.char {
2425
var JID defproto.JID
2526
proto.Unmarshal(getByteByAddr(user, userSize), &JID)
26-
err := clients[C.GoString(id)].Store.ChatSettings.PutMutedUntil(utils.DecodeJidProto(&JID), time.Unix(int64(mutedUntil), 0))
27+
err := clients[C.GoString(id)].Store.ChatSettings.PutMutedUntil(context.Background(), utils.DecodeJidProto(&JID), time.Unix(int64(mutedUntil), 0))
2728
if err != nil {
2829
return C.CString(err.Error())
2930
}
@@ -34,7 +35,7 @@ func PutMutedUntil(id *C.char, user *C.uchar, userSize C.int, mutedUntil C.float
3435
func GetChatSettings(id *C.char, user *C.uchar, userSize C.int) C.struct_BytesReturn {
3536
var JID defproto.JID
3637
proto.Unmarshal(getByteByAddr(user, userSize), &JID)
37-
local_chat_settings, err := clients[C.GoString(id)].Store.ChatSettings.GetChatSettings(utils.DecodeJidProto(&JID))
38+
local_chat_settings, err := clients[C.GoString(id)].Store.ChatSettings.GetChatSettings(context.Background(), utils.DecodeJidProto(&JID))
3839
return_ := defproto.ReturnFunctionWithError{}
3940
if err != nil {
4041
return_.Error = proto.String(err.Error())

goneonize/contact_store.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import (
77
"github.com/krypton-byte/neonize/utils"
88
"google.golang.org/protobuf/proto"
99
)
10-
import "go.mau.fi/whatsmeow/store"
10+
import (
11+
"context"
12+
13+
"go.mau.fi/whatsmeow/store"
14+
)
1115

1216
//export PutPushName
1317
func PutPushName(id *C.char, user *C.uchar, userSize C.int, pushname *C.char) C.struct_BytesReturn {
@@ -17,7 +21,7 @@ func PutPushName(id *C.char, user *C.uchar, userSize C.int, pushname *C.char) C.
1721
panic(err)
1822
}
1923
return_ := defproto.ContactsPutPushNameReturnFunction{}
20-
status, prev_name, err := clients[C.GoString(id)].Store.Contacts.PutPushName(utils.DecodeJidProto(&userJID), C.GoString(pushname))
24+
status, prev_name, err := clients[C.GoString(id)].Store.Contacts.PutPushName(context.Background(), utils.DecodeJidProto(&userJID), C.GoString(pushname))
2125
return_.PreviousName = proto.String(prev_name)
2226
return_.Status = &status
2327
if err != nil {
@@ -38,7 +42,7 @@ func PutBusinessName(id *C.char, user *C.uchar, userSize C.int, businessName *C.
3842
panic(err)
3943
}
4044
return_ := defproto.ContactsPutPushNameReturnFunction{}
41-
status, prev_name, err := clients[C.GoString(id)].Store.Contacts.PutBusinessName(utils.DecodeJidProto(&userJID), C.GoString(businessName))
45+
status, prev_name, err := clients[C.GoString(id)].Store.Contacts.PutBusinessName(context.Background(), utils.DecodeJidProto(&userJID), C.GoString(businessName))
4246
return_.PreviousName = proto.String(prev_name)
4347
return_.Status = &status
4448
if err != nil {
@@ -58,7 +62,7 @@ func PutContactName(id *C.char, user *C.uchar, userSize C.int, fullName, firstNa
5862
if err != nil {
5963
panic(err)
6064
}
61-
err_ := clients[C.GoString(id)].Store.Contacts.PutContactName(utils.DecodeJidProto(&userJID), C.GoString(fullName), C.GoString(firstName))
65+
err_ := clients[C.GoString(id)].Store.Contacts.PutContactName(context.Background(), utils.DecodeJidProto(&userJID), C.GoString(fullName), C.GoString(firstName))
6266
if err_ != nil {
6367
return C.CString(err_.Error())
6468
}
@@ -76,7 +80,7 @@ func PutAllContactNames(id *C.char, contacts *C.uchar, contactsSize C.int) *C.ch
7680
for i, centry := range entry.ContactEntry {
7781
contactEntry[i] = *utils.DecodeContactEntry(centry)
7882
}
79-
err_r := clients[C.GoString(id)].Store.Contacts.PutAllContactNames(contactEntry)
83+
err_r := clients[C.GoString(id)].Store.Contacts.PutAllContactNames(context.Background(), contactEntry)
8084
if err_r != nil {
8185
return C.CString(err_r.Error())
8286
}
@@ -90,7 +94,7 @@ func GetContact(id *C.char, user *C.uchar, userSize C.int) C.struct_BytesReturn
9094
if err != nil {
9195
panic(err)
9296
}
93-
contact_info, err_ := clients[C.GoString(id)].Store.Contacts.GetContact(utils.DecodeJidProto(&userJID))
97+
contact_info, err_ := clients[C.GoString(id)].Store.Contacts.GetContact(context.Background(), utils.DecodeJidProto(&userJID))
9498
return_ := defproto.ContactsGetContactReturnFunction{
9599
ContactInfo: utils.EncodeContactInfo(contact_info),
96100
}
@@ -106,7 +110,7 @@ func GetContact(id *C.char, user *C.uchar, userSize C.int) C.struct_BytesReturn
106110

107111
//export GetAllContacts
108112
func GetAllContacts(id *C.char) C.struct_BytesReturn {
109-
contacts, err := clients[C.GoString(id)].Store.Contacts.GetAllContacts()
113+
contacts, err := clients[C.GoString(id)].Store.Contacts.GetAllContacts(context.Background())
110114
return_ := defproto.ContactsGetAllContactsReturnFunction{
111115
Contact: utils.EncodeContacts(contacts),
112116
}

0 commit comments

Comments
 (0)