Skip to content

Commit

Permalink
feat: send presence
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Oct 27, 2024
1 parent f43f319 commit f27e968
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
9 changes: 9 additions & 0 deletions goneonize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,15 @@ func GetAllDevices(db *C.char) *C.char {
return C.CString(result.String())
}

//export SendPresence
func SendPresence(id *C.char, presence *C.char) *C.char {
err := clients[C.GoString(id)].SendPresence(types.Presence(C.GoString(presence)))
if err != nil {
return C.CString(err.Error())
}
return C.CString("")
}

//export SendFBMessage
func SendFBMessage(id *C.char, to *C.uchar, toSize C.int, message *C.uchar, messageSize C.int, metadata *C.uchar, metadataSize C.int, extra *C.uchar, extraSize C.int) C.struct_BytesReturn {
var toJID defproto.JID
Expand Down
5 changes: 5 additions & 0 deletions neonize/_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,10 @@ def get_bytes(self):
ctypes.c_int,
]
gocode.SendFBMessage.restype = Bytes
gocode.SendPresence.argtypes = [
ctypes.c_char_p,
ctypes.c_char_p
]
gocode.SendPresence.restype = ctypes.c_char_p
else:
gocode: Any = object()
10 changes: 9 additions & 1 deletion neonize/aioze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
ChatPresenceMedia,
LogLevel,
ParticipantChange,
Presence,
ReceiptType,
ClientType,
ClientName,
Expand Down Expand Up @@ -105,6 +106,7 @@
ResolveContactQRLinkError,
SendAppStateError,
SendMessageError,
SendPresenceError,
SetDefaultDisappearingTimerError,
SetDisappearingTimerError,
SetGroupAnnounceError,
Expand Down Expand Up @@ -2670,7 +2672,13 @@ async def send_fb_message(
len(extra_buff),
)
return SendResponse.FromString(response.get_bytes())

async def send_presence(self, presence: Presence):
response = await self.__client.SendPresence(
self.uuid,
presence.value
)
if response:
raise SendPresenceError(response)
async def connect(self):
"""Establishes a connection to the WhatsApp servers."""
# Convert the list of functions to a bytearray
Expand Down
10 changes: 9 additions & 1 deletion neonize/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
PutPinnedError,
ResolveContactQRLinkError,
SendAppStateError,
SendPresenceError,
SetDefaultDisappearingTimerError,
SetDisappearingTimerError,
SetGroupAnnounceError,
Expand Down Expand Up @@ -146,6 +147,7 @@
ChatPresenceMedia,
LogLevel,
ParticipantChange,
Presence,
ReceiptType,
ClientType,
ClientName,
Expand Down Expand Up @@ -2520,7 +2522,13 @@ def send_fb_message(
len(extra_buff),
)
return SendResponse.FromString(response.get_bytes())

def send_presence(self, presence: Presence):
response = self.__client.SendPresence(
self.uuid,
presence.value
)
if response:
raise SendPresenceError(response)
def connect(self):
"""Establishes a connection to the WhatsApp servers."""
# Convert the list of functions to a bytearray
Expand Down
7 changes: 7 additions & 0 deletions neonize/exc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# class InvalidInviteLink(Exception):
# pass
from re import L


class UploadError(Exception):
pass

Expand Down Expand Up @@ -234,3 +237,7 @@ class PutArchivedError(Exception):

class GetChatSettingsError(Exception):
pass


class SendPresenceError(Exception):
pass
4 changes: 4 additions & 0 deletions neonize/utils/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,7 @@ class ParticipantRequestChange(Enum):

APPROVE = "approve"
REJECT = "reject"

class Presence(Enum):
AVAILABLE = b"available"
UNAVAILABLE = b"unavailable"

0 comments on commit f27e968

Please sign in to comment.