Skip to content

NewClient

neonize.client.NewClient

Python
NewClient(name: str, jid: Optional[JID] = None, props: Optional[DeviceProps] = None, uuid: Optional[str] = None)

Initializes a new client instance.

PARAMETER DESCRIPTION
name

The name or identifier for the new client.

TYPE: str

jid

Optional. The JID (Jabber Identifier) for the client. If not provided, first client is used.

TYPE: Optional[JID] DEFAULT: None

qrCallback

Optional. A callback function for handling QR code updates, defaults to None.

TYPE: (Optional[Callable[[NewClient, bytes], None]], optional)

messageCallback

Optional. A callback function for handling incoming messages, defaults to None.

TYPE: (Optional[Callable[[NewClient, MessageSource, Message], None]], optional)

uuid

Optional. A unique identifier for the client, defaults to None.

TYPE: Optional[str] DEFAULT: None

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def __init__(
    self,
    name: str,
    jid: Optional[JID] = None,
    props: Optional[DeviceProps] = None,
    uuid: Optional[str] = None,
):
    """Initializes a new client instance.

    :param name: The name or identifier for the new client.
    :type name: str
    :param jid: Optional. The JID (Jabber Identifier) for the client. If not provided, first client is used.
    :param qrCallback: Optional. A callback function for handling QR code updates, defaults to None.
    :type qrCallback: Optional[Callable[[NewClient, bytes], None]], optional
    :param messageCallback: Optional. A callback function for handling incoming messages, defaults to None.
    :type messageCallback: Optional[Callable[[NewClient, MessageSource, Message], None]], optional
    :param uuid: Optional. A unique identifier for the client, defaults to None.
    :type uuid: Optional[str], optional
    """
    self.name = name
    self.device_props = props
    self.jid = jid
    self.uuid = (jid.User if jid else (uuid or name)).encode()
    self.__client = gocode
    self.event = Event(self)
    self.qr = self.event.qr
    self.contact = ContactStore(self.uuid)
    self.chat_settings = ChatSettingsStore(self.uuid)
    self.connected = False
    self.me = None
    _log_.debug("🔨 Creating a NewClient instance")

Attributes

is_connected property

Python
is_connected: bool

Check if the object is currently connected.

RETURNS DESCRIPTION
bool

True if the object is connected, False otherwise.

is_logged_in property

Python
is_logged_in: bool

Check if the user is currently logged in.

RETURNS DESCRIPTION
bool

True if the user is logged in, False otherwise.

Functions

send_message

Python
send_message(to: JID, message: Union[Message, str], link_preview: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> SendResponse

Send a message to the specified JID.

PARAMETER DESCRIPTION
to

The JID to send the message to.

TYPE: JID

message

The message to send.

TYPE: Union[Message, str]

link_preview

Whether to send a link preview, defaults to False

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

The response from the server.

RAISES DESCRIPTION
SendMessageError

If there was an error sending the message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_message(
    self,
    to: JID,
    message: typing.Union[Message, str],
    link_preview: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Send a message to the specified JID.

    :param to: The JID to send the message to.
    :type to: JID
    :param message: The message to send.
    :type message: typing.Union[Message, str]
    :param link_preview: Whether to send a link preview, defaults to False
    :type link_preview: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :param add_msg_secret: Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :raises SendMessageError: If there was an error sending the message.
    :return: The response from the server.
    :rtype: SendResponse
    """
    to_bytes = to.SerializeToString()
    if isinstance(message, str):
        mentioned_groups = self._parse_group_mention(message)
        mentioned_jid = self._parse_mention(
            (ghost_mentions or message), mentions_are_lids
        )
        partial_msg = ExtendedTextMessage(
            text=message,
            contextInfo=ContextInfo(
                mentionedJID=mentioned_jid, groupMentions=mentioned_groups
            ),
        )
        if link_preview:
            preview = self._generate_link_preview(message)
            if preview:
                partial_msg.MergeFrom(preview)
        if partial_msg.previewType is None and not (
            mentioned_groups or mentioned_jid
        ):
            msg = Message(conversation=message)
        else:
            msg = Message(extendedTextMessage=partial_msg)
    else:
        msg = message
    if add_msg_secret:
        msg.messageContextInfo.messageSecret = urandom(32)
    message_bytes = msg.SerializeToString()
    bytes_ptr = self.__client.SendMessage(
        self.uuid, to_bytes, len(to_bytes), message_bytes, len(message_bytes)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = SendMessageReturnFunction.FromString(protobytes)
    if model.Error:
        raise SendMessageError(model.Error)
    model.SendResponse.MergeFrom(model.SendResponse.__class__(Message=msg))
    return model.SendResponse

build_reply_message

Python
build_reply_message(message: Union[str, MessageWithContextInfo], quoted: Message, link_preview: bool = False, reply_privately: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False) -> Message

Send a reply message to a specified JID.

PARAMETER DESCRIPTION
message

The message to be sent. Can be a string or a MessageWithContextInfo object.

TYPE: Union[str, MessageWithContextInfo]

quoted

The message to be quoted in the message being sent.

TYPE: Message

link_preview

If set to True, enables link previews in the message being sent. Defaults to False.

TYPE: bool DEFAULT: False

reply_privately

If set to True, the message is sent as a private reply. Defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

Response of the send operation.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_reply_message(
    self,
    message: typing.Union[str, MessageWithContextInfo],
    quoted: neonize_proto.Message,
    link_preview: bool = False,
    reply_privately: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
) -> Message:
    """Send a reply message to a specified JID.

    :param message: The message to be sent. Can be a string or a MessageWithContextInfo object.
    :type message: typing.Union[str, MessageWithContextInfo]
    :param quoted: The message to be quoted in the message being sent.
    :type quoted: neonize_proto.Message
    :param link_preview: If set to True, enables link previews in the message being sent. Defaults to False.
    :type link_preview: bool, optional
    :param reply_privately: If set to True, the message is sent as a private reply. Defaults to False.
    :type reply_privately: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :return: Response of the send operation.
    :rtype: SendResponse
    """
    build_message = Message()
    if isinstance(message, str):
        partial_message = ExtendedTextMessage(
            text=message,
            contextInfo=ContextInfo(
                mentionedJID=self._parse_mention(
                    (ghost_mentions or message), mentions_are_lids
                ),
                groupMentions=(self._parse_group_mention(message)),
            ),
        )
        if link_preview:
            preview = self._generate_link_preview(message)
            if preview is not None:
                partial_message.MergeFrom(preview)
    else:
        partial_message = message
    field_name = (
        partial_message.__class__.__name__[0].lower()
        + partial_message.__class__.__name__[1:]
    )  # type: ignore
    partial_message.contextInfo.MergeFrom(
        self._make_quoted_message(quoted, reply_privately)
    )
    getattr(build_message, field_name).MergeFrom(partial_message)
    return build_message

reply_message

Python
reply_message(message: Union[str, MessageWithContextInfo], quoted: Message, to: Optional[JID] = None, link_preview: bool = False, reply_privately: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> SendResponse

Send a reply message to a specified JID.

PARAMETER DESCRIPTION
message

The message to be sent. Can be a string or a MessageWithContextInfo object.

TYPE: Union[str, MessageWithContextInfo]

quoted

The message to be quoted in the message being sent.

TYPE: Message

to

The recipient of the message. If not specified, the message is sent to the default recipient.

TYPE: Optional[JID] DEFAULT: None

link_preview

If set to True, enables link previews in the message being sent. Defaults to False.

TYPE: bool DEFAULT: False

reply_privately

If set to True, the message is sent as a private reply. Defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

If set to True generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

Response of the send operation.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def reply_message(
    self,
    message: typing.Union[str, MessageWithContextInfo],
    quoted: neonize_proto.Message,
    to: Optional[JID] = None,
    link_preview: bool = False,
    reply_privately: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Send a reply message to a specified JID.

    :param message: The message to be sent. Can be a string or a MessageWithContextInfo object.
    :type message: typing.Union[str, MessageWithContextInfo]
    :param quoted: The message to be quoted in the message being sent.
    :type quoted: neonize_proto.Message
    :param to: The recipient of the message. If not specified, the message is sent to the default recipient.
    :type to: Optional[JID], optional
    :param link_preview: If set to True, enables link previews in the message being sent. Defaults to False.
    :type link_preview: bool, optional
    :param reply_privately: If set to True, the message is sent as a private reply. Defaults to False.
    :type reply_privately: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :param add_msg_secret: If set to True generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: Response of the send operation.
    :rtype: SendResponse
    """
    if to is None:
        if reply_privately:
            sender = quoted.Info.MessageSource.Sender
            if jid_is_lid(sender):
                sender = quoted.Info.MessageSource.SenderAlt or sender
            to = JIDToNonAD(sender)
        else:
            to = quoted.Info.MessageSource.Chat
    return self.send_message(
        to,
        self.build_reply_message(
            message=message,
            quoted=quoted,
            link_preview=link_preview,
            reply_privately=reply_privately,
            ghost_mentions=ghost_mentions,
            mentions_are_lids=mentions_are_lids,
        ),
        link_preview,
        add_msg_secret=add_msg_secret,
    )

edit_message

Python
edit_message(chat: JID, message_id: str, new_message: Message) -> SendResponse

Edit a message.

PARAMETER DESCRIPTION
chat

Chat ID

TYPE: JID

message_id

Message ID

TYPE: str

new_message

New message

TYPE: Message

RETURNS DESCRIPTION
SendResponse

Response from server

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def edit_message(
    self, chat: JID, message_id: str, new_message: Message
) -> SendResponse:
    """Edit a message.

    :param chat: Chat ID
    :type chat: JID
    :param message_id: Message ID
    :type message_id: str
    :param new_message: New message
    :type new_message: Message
    :return: Response from server
    :rtype: SendResponse
    """
    return self.send_message(chat, build_edit(chat, message_id, new_message))

revoke_message

Python
revoke_message(chat: JID, sender: JID, message_id: str) -> SendResponse

Revoke a message.

PARAMETER DESCRIPTION
chat

Chat ID

TYPE: JID

sender

Sender ID

TYPE: JID

message_id

Message ID

TYPE: str

RETURNS DESCRIPTION
SendResponse

Response from server

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def revoke_message(self, chat: JID, sender: JID, message_id: str) -> SendResponse:
    """Revoke a message.

    :param chat: Chat ID
    :type chat: JID
    :param sender: Sender ID
    :type sender: JID
    :param message_id: Message ID
    :type message_id: str
    :return: Response from server
    :rtype: SendResponse
    """
    return self.send_message(chat, self.build_revoke(chat, sender, message_id))

build_poll_vote_creation

Python
build_poll_vote_creation(name: str, options: List[str], selectable_count: VoteType, quoted: Optional[Message] = None) -> Message

Build a poll vote creation message.

PARAMETER DESCRIPTION
name

The name of the poll.

TYPE: str

options

The options for the poll.

TYPE: List[str]

selectable_count

The number of selectable options.

TYPE: VoteType

quoted

A message that the poll message is a reply to, defaults to None

TYPE: Optional[Message] DEFAULT: None

RETURNS DESCRIPTION
Message

The poll vote creation message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_poll_vote_creation(
    self,
    name: str,
    options: List[str],
    selectable_count: VoteType,
    quoted: Optional[neonize_proto.Message] = None,
) -> Message:
    """Build a poll vote creation message.

    :param name: The name of the poll.
    :type name: str
    :param options: The options for the poll.
    :type options: List[str]
    :param selectable_count: The number of selectable options.
    :type selectable_count: int
    :param quoted: A message that the poll message is a reply to, defaults to None
    :type quoted: Optional[neonize_proto.Message], optional
    :return: The poll vote creation message.
    :rtype: Message
    """
    options_buf = neonize_proto.ArrayString(data=options).SerializeToString()
    bytes_ptr = self.__client.BuildPollVoteCreation(
        self.uuid,
        name.encode(),
        options_buf,
        len(options_buf),
        selectable_count.value,
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = BuildMessageReturnFunction.FromString(protobytes)
    if model.Error:
        raise BuildPollVoteCreationError(model.Error)
    message = model.Message

    if quoted:
        message.pollCreationMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return message

build_poll_vote

Python
build_poll_vote(poll_info: MessageInfo, option_names: List[str]) -> Message

Builds a poll vote.

PARAMETER DESCRIPTION
poll_info

The information about the poll.

TYPE: MessageInfo

option_names

The names of the options to vote for.

TYPE: List[str]

RETURNS DESCRIPTION
Message

The poll vote message.

RAISES DESCRIPTION
BuildPollVoteError

If there is an error building the poll vote.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_poll_vote(
    self, poll_info: MessageInfo, option_names: List[str]
) -> Message:
    """Builds a poll vote.

    :param poll_info: The information about the poll.
    :type poll_info: MessageInfo
    :param option_names: The names of the options to vote for.
    :type option_names: List[str]
    :return: The poll vote message.
    :rtype: Message
    :raises BuildPollVoteError: If there is an error building the poll vote.
    """
    option_names_proto = neonize_proto.ArrayString(
        data=option_names
    ).SerializeToString()
    poll_info_proto = poll_info.SerializeToString()
    bytes_ptr = self.__client.BuildPollVote(
        self.uuid,
        poll_info_proto,
        len(poll_info_proto),
        option_names_proto,
        len(option_names_proto),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.BuildPollVoteReturnFunction.FromString(protobytes)
    if model.Error:
        raise BuildPollVoteError(model.Error)
    return model.PollVote

build_reaction

Python
build_reaction(chat: JID, sender: JID, message_id: str, reaction: str) -> Message

This function builds a reaction message in a chat. It takes the chat and sender IDs, the message ID to which the reaction is being made, and the reaction itself as input. It then serializes the chat and sender IDs to strings, and calls the BuildReaction function of the client with these serialized IDs, the message ID, and the reaction. It finally returns the reaction message.

PARAMETER DESCRIPTION
chat

The ID of the chat in which the reaction is being made

TYPE: JID

sender

The ID of the sender making the reaction

TYPE: JID

message_id

The ID of the message to which the reaction is being made

TYPE: str

reaction

The reaction being made

TYPE: str

RETURNS DESCRIPTION
Message

The reaction message

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_reaction(
    self, chat: JID, sender: JID, message_id: str, reaction: str
) -> Message:
    """
    This function builds a reaction message in a chat. It takes the chat and sender IDs,
    the message ID to which the reaction is being made, and the reaction itself as input.
    It then serializes the chat and sender IDs to strings, and calls the BuildReaction
    function of the client with these serialized IDs, the message ID, and the reaction.
    It finally returns the reaction message.

    :param chat: The ID of the chat in which the reaction is being made
    :type chat: JID
    :param sender: The ID of the sender making the reaction
    :type sender: JID
    :param message_id: The ID of the message to which the reaction is being made
    :type message_id: str
    :param reaction: The reaction being made
    :type reaction: str
    :return: The reaction message
    :rtype: Message
    """
    sender_proto = sender.SerializeToString()
    chat_proto = chat.SerializeToString()
    bytes_ptr = self.__client.BuildReaction(
        self.uuid,
        chat_proto,
        len(chat_proto),
        sender_proto,
        len(sender_proto),
        message_id.encode(),
        reaction.encode(),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    result = BuildMessageReturnFunction.FromString(protobytes)
    if result.Error:
        raise SendMessageError(result.Error)
    return result.Message

build_revoke

Python
build_revoke(chat: JID, sender: JID, message_id: str, with_go: bool = False) -> Message

Builds a message to revoke a previous message.

PARAMETER DESCRIPTION
chat

The JID (Jabber Identifier) of the chat where the message should be revoked.

TYPE: JID

sender

The JID of the sender of the message to be revoked.

TYPE: JID

message_id

The unique identifier of the message to be revoked.

TYPE: str

RETURNS DESCRIPTION
Message

The constructed Message object for revoking the specified message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_revoke(
    self, chat: JID, sender: JID, message_id: str, with_go: bool = False
) -> Message:
    """Builds a message to revoke a previous message.

    :param chat: The JID (Jabber Identifier) of the chat where the message should be revoked.
    :type chat: JID
    :param sender: The JID of the sender of the message to be revoked.
    :type sender: JID
    :param message_id: The unique identifier of the message to be revoked.
    :type message_id: str
    :return: The constructed Message object for revoking the specified message.
    :rtype: Message
    """
    if with_go:
        chat_buf = chat.SerializeToString()
        sender_buf = sender.SerializeToString()
        bytes_ptr = self.__client.BuildRevoke(
            self.uuid,
            chat_buf,
            len(chat_buf),
            sender_buf,
            len(sender_buf),
            message_id.encode(),
        )
        protobytes = bytes_ptr.contents.get_bytes()
        free_bytes(bytes_ptr)
        result = Message.FromString(protobytes)
        return result
    else:
        return build_revoke(chat, sender, message_id, self.get_me().JID)

build_sticker_message

Python
build_sticker_message(file: Union[str, bytes], quoted: Optional[Message] = None, name: str = '', packname: str = '', crop: bool = False, enforce_not_broken: bool = False, animated_gif: bool = False, passthrough: bool = False) -> Message

This function builds a sticker message from a given image or video file. The file is converted to a webp format and uploaded to a server. The resulting URL and other metadata are used to construct the sticker message.

PARAMETER DESCRIPTION
file

The path to the image or video file or the file data in bytes

TYPE: Union[str, bytes]

quoted

A message that the sticker message is a reply to, defaults to None

TYPE: Optional[Message] DEFAULT: None

name

The name of the sticker, defaults to ""

TYPE: str DEFAULT: ''

packname

The name of the sticker pack, defaults to ""

TYPE: str DEFAULT: ''

crop

Crop-center the image, defaults to False

TYPE: bool DEFAULT: False

enforce_not_broken

Enforce non-broken stickers by constraining sticker size to WA limits, defaults to False

TYPE: bool DEFAULT: False

animated_gif

Ensure transparent media are properly processed, defaults to False

TYPE: bool DEFAULT: False

passthrough

Don't process sticker, send as is, defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Message

The constructed sticker message

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_sticker_message(
    self,
    file: typing.Union[str, bytes],
    quoted: Optional[neonize_proto.Message] = None,
    name: str = "",
    packname: str = "",
    crop: bool = False,
    enforce_not_broken: bool = False,
    animated_gif: bool = False,
    passthrough: bool = False,
) -> Message:
    """
    This function builds a sticker message from a given image or video file.
    The file is converted to a webp format and uploaded to a server.
    The resulting URL and other metadata are used to construct the sticker message.

    :param file: The path to the image or video file or the file data in bytes
    :type file: typing.Union[str, bytes]
    :param quoted: A message that the sticker message is a reply to, defaults to None
    :type quoted: Optional[neonize_proto.Message], optional
    :param name: The name of the sticker, defaults to ""
    :type name: str, optional
    :param packname: The name of the sticker pack, defaults to ""
    :type packname: str, optional
    :param crop: Crop-center the image, defaults to False
    :type crop: bool, optional
    :param enforce_not_broken: Enforce non-broken stickers by constraining sticker size to WA limits, defaults to False
    :type enforce_not_broken: bool, optional
    :param animated_gif: Ensure transparent media are properly processed, defaults to False
    :type animated_gif: bool, optional
    :param passthrough: Don't process sticker, send as is, defaults to False.
    :type passthrough: bool, optional
    :return: The constructed sticker message
    :rtype: Message
    """
    sticker = get_bytes_from_name_or_url(file)
    animated = is_webm = is_webp = is_image = saved_exif = False
    mime = magic.from_buffer(sticker, mime=True)
    if mime == "image/webp":
        is_webp = True
        io_save = BytesIO(sticker)
        img = Image.open(io_save)
        if len(ImageSequence.all_frames(img)) < 2:
            is_image = True
    elif mime == "video/webm":
        is_webm = True
    elif (mime := mime.split("/"))[0] == "image":
        is_image = True
    animated = not (is_image)
    if not passthrough and not animated_gif and is_image:
        io_save = BytesIO(sticker)
        stk = auto_sticker(io_save) if crop else original_sticker(io_save)
        io_save = BytesIO()
        # io_save.seek(0)
    elif not passthrough:
        animated = True
        sticker, saved_exif = convert_to_sticker(
            sticker, name, packname, enforce_not_broken, animated_gif, is_webm
        )
        if saved_exif:
            io_save = BytesIO(sticker)
        else:
            stk = Image.open(BytesIO(sticker))
            io_save = BytesIO()
    else:
        if not is_webp:
            raise ConvertStickerError(
                "File is not a webp, which is required for passthrough."
            )
    if not (passthrough or saved_exif):
        stk.save(
            io_save,
            format="webp",
            exif=add_exif(name, packname),
            save_all=True,
            loop=0,
        )
    upload = self.upload(io_save.getvalue())
    message = Message(
        stickerMessage=StickerMessage(
            URL=upload.url,
            directPath=upload.DirectPath,
            fileEncSHA256=upload.FileEncSHA256,
            fileLength=upload.FileLength,
            fileSHA256=upload.FileSHA256,
            mediaKey=upload.MediaKey,
            mimetype=magic.from_buffer(io_save.getvalue(), mime=True),
            isAnimated=animated,
        )
    )
    if quoted:
        message.stickerMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return message

send_sticker

Python
send_sticker(to: JID, file: Union[str, bytes], quoted: Optional[Message] = None, name: str = '', packname: str = '', crop: bool = False, enforce_not_broken: bool = False, animated_gif: bool = False, passthrough: bool = False, add_msg_secret: bool = False) -> SendResponse

Send a sticker to a specific JID.

PARAMETER DESCRIPTION
to

The JID to send the sticker to.

TYPE: JID

file

The file path of the sticker or the sticker data in bytes.

TYPE: Union[str, bytes]

quoted

The quoted message, if any, defaults to None.

TYPE: Optional[Message] DEFAULT: None

name

The name of the sticker, defaults to "".

TYPE: str DEFAULT: ''

packname

The name of the sticker pack, defaults to "".

TYPE: str DEFAULT: ''

crop

Whether to crop-center the image, defaults to False

TYPE: bool DEFAULT: False

enforce_not_broken

Whether to enforce non-broken stickers by constraining sticker size to WA limits, defaults to False

TYPE: bool DEFAULT: False

animated_gif

Ensure transparent media are properly processed, defaults to False

TYPE: bool DEFAULT: False

passthrough

Don't process sticker, send as is, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

The response from the send message function.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_sticker(
    self,
    to: JID,
    file: typing.Union[str, bytes],
    quoted: Optional[neonize_proto.Message] = None,
    name: str = "",
    packname: str = "",
    crop: bool = False,
    enforce_not_broken: bool = False,
    animated_gif: bool = False,
    passthrough: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """
    Send a sticker to a specific JID.

    :param to: The JID to send the sticker to.
    :type to: JID
    :param file: The file path of the sticker or the sticker data in bytes.
    :type file: typing.Union[str, bytes]
    :param quoted: The quoted message, if any, defaults to None.
    :type quoted: Optional[neonize_proto.Message], optional
    :param name: The name of the sticker, defaults to "".
    :type name: str, optional
    :param packname: The name of the sticker pack, defaults to "".
    :type packname: str, optional
    :param crop: Whether to crop-center the image, defaults to False
    :type crop: bool, optional
    :param enforce_not_broken: Whether to enforce non-broken stickers by constraining sticker size to WA limits, defaults to False
    :type enforce_not_broken: bool, optional
    :param animated_gif: Ensure transparent media are properly processed, defaults to False
    :type animated_gif: bool, optional
    :param passthrough: Don't process sticker, send as is, defaults to False.
    :type passthrough: bool, optional
    :param add_msg_secret: Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: The response from the send message function.
    :rtype: SendResponse
    """
    return self.send_message(
        to,
        self.build_sticker_message(
            file,
            quoted,
            name,
            packname,
            crop,
            enforce_not_broken,
            animated_gif,
            passthrough,
        ),
        add_msg_secret=add_msg_secret,
    )

send_stickerpack

Python
send_stickerpack(to: JID, files: list, quoted: Optional[Message] = None, packname: str = 'Sticker pack', publisher: str = '', crop: bool = False, animated_gif: bool = False, passthrough: bool = False, add_msg_secret: bool = False) -> List[SendResponse]

Send a sticker pack to a specific JID.

PARAMETER DESCRIPTION
to

The JID to send the sticker to.

TYPE: JID

files

A list of file paths of the stickers or a list of stickers data in bytes.

TYPE: list

quoted

The quoted message, if any, defaults to None.

TYPE: Optional[Message] DEFAULT: None

packname

The name of the sticker pack, defaults to "Sticker pack".

TYPE: str DEFAULT: 'Sticker pack'

publisher

The name of the publisher, defaults to "".

TYPE: str DEFAULT: ''

crop

Whether to crop-center the image, defaults to False

TYPE: bool DEFAULT: False

add_msg_secret

Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
List[SendResponse]

A list of response(s) from the send message function.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_stickerpack(
    self,
    to: JID,
    files: list,
    quoted: Optional[neonize_proto.Message] = None,
    packname: str = "Sticker pack",
    publisher: str = "",
    crop: bool = False,
    animated_gif: bool = False,
    passthrough: bool = False,
    add_msg_secret: bool = False,
) -> List[SendResponse]:
    """
    Send a sticker pack to a specific JID.

    :param to: The JID to send the sticker to.
    :type to: JID
    :param files:  A list of file paths of the stickers or a list of stickers data in bytes.
    :type file: List[typing.Union[str, bytes]]
    :param quoted: The quoted message, if any, defaults to None.
    :type quoted: Optional[neonize_proto.Message], optional
    :param packname: The name of the sticker pack, defaults to "Sticker pack".
    :type packname: str, optional
    :param publisher: The name of the publisher, defaults to "".
    :type publisher: str, optional
    :param crop: Whether to crop-center the image, defaults to False
    :type crop: bool, optional
    :param add_msg_secret: Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A list of response(s) from the send message function.
    :rtype: List[SendResponse]
    """
    responses = []
    msgs = self.build_stickerpack_message(
        files, quoted, packname, publisher, crop, animated_gif, passthrough
    )
    for msg in msgs:
        response = self.send_message(
            to,
            msg,
            add_msg_secret=add_msg_secret,
        )
        responses.append(response)
    return responses

build_video_message

Python
build_video_message(file: str | bytes, caption: Optional[str] = None, quoted: Optional[Message] = None, viewonce: bool = False, gifplayback: bool = False, is_gif: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False) -> Message

This function is used to build a video message. It uploads a video file, extracts necessary information, and constructs a message with the given parameters.

PARAMETER DESCRIPTION
file

The file path or bytes of the video file to be uploaded.

TYPE: str | bytes

caption

The caption to be added to the video message, defaults to None

TYPE: Optional[str] DEFAULT: None

quoted

A message that the video message is in response to, defaults to None

TYPE: Optional[Message] DEFAULT: None

viewonce

A flag indicating if the video message can be viewed only once, defaults to False

TYPE: bool DEFAULT: False

gifplayback

Optional. Whether the video should be sent as gif. Defaults to False.

TYPE: bool DEFAULT: False

is_gif

Optional. Whether the video to be sent is a gif. Defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Message

A video message with the given parameters.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_video_message(
    self,
    file: str | bytes,
    caption: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    viewonce: bool = False,
    gifplayback: bool = False,
    is_gif: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
) -> Message:
    """
    This function is used to build a video message. It uploads a video file, extracts necessary information,
    and constructs a message with the given parameters.

    :param file: The file path or bytes of the video file to be uploaded.
    :type file: str | bytes
    :param caption: The caption to be added to the video message, defaults to None
    :type caption: Optional[str], optional
    :param quoted: A message that the video message is in response to, defaults to None
    :type quoted: Optional[neonize_proto.Message], optional
    :param viewonce: A flag indicating if the video message can be viewed only once, defaults to False
    :type viewonce: bool, optional
    :param gifplayback: Optional. Whether the video should be sent as gif. Defaults to False.
    :type gifplayback: bool, optional
    :param is_gif: Optional. Whether the video to be sent is a gif. Defaults to False.
    :type is_gif: bool, optional
    :return: A video message with the given parameters.
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :rtype: Message
    """
    io = BytesIO(get_bytes_from_name_or_url(file))
    io.seek(0)
    buff = io.read()
    if is_gif:
        with FFmpeg(file) as ffmpeg:
            buff = file = ffmpeg.gif_to_mp4()
    with FFmpeg(file) as ffmpeg:
        duration = int(ffmpeg.extract_info().format.duration)
        thumbnail = ffmpeg.extract_thumbnail()
    upload = self.upload(buff)
    message = Message(
        videoMessage=VideoMessage(
            URL=upload.url,
            caption=caption,
            gifPlayback=gifplayback,
            seconds=duration,
            directPath=upload.DirectPath,
            fileEncSHA256=upload.FileEncSHA256,
            fileLength=upload.FileLength,
            fileSHA256=upload.FileSHA256,
            mediaKey=upload.MediaKey,
            mimetype=magic.from_buffer(buff, mime=True),
            JPEGThumbnail=thumbnail,
            thumbnailDirectPath=upload.DirectPath,
            thumbnailEncSHA256=upload.FileEncSHA256,
            thumbnailSHA256=upload.FileSHA256,
            viewOnce=viewonce,
            contextInfo=ContextInfo(
                mentionedJID=self._parse_mention(
                    (ghost_mentions or caption), mentions_are_lids
                ),
                groupMentions=(self._parse_group_mention(caption)),
            ),
        )
    )
    if quoted:
        message.videoMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return message

send_video

Python
send_video(to: JID, file: str | bytes, caption: Optional[str] = None, quoted: Optional[Message] = None, viewonce: bool = False, gifplayback: bool = False, is_gif: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> SendResponse

Sends a video to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

file

Either a file path (str), url (str) or binary data (bytes) representing the video.

TYPE: str | bytes

caption

Optional. The caption of the video. Defaults to None.

TYPE: Optional[str] DEFAULT: None

quoted

Optional. The message to which the video is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

viewonce

Optional. Whether the video should be viewonce. Defaults to False.

TYPE: bool DEFAULT: False

gifplayback

Optional. Whether the video should be sent as gif. Defaults to False.

TYPE: bool DEFAULT: False

is_gif

Optional. Whether the video to be sent is a gif. Defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

A function for handling the result of the video sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_video(
    self,
    to: JID,
    file: str | bytes,
    caption: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    viewonce: bool = False,
    gifplayback: bool = False,
    is_gif: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Sends a video to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param file: Either a file path (str), url (str) or binary data (bytes) representing the video.
    :type file: typing.Union[str | bytes]
    :param caption: Optional. The caption of the video. Defaults to None.
    :type caption: Optional[str], optional
    :param quoted: Optional. The message to which the video is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :param viewonce: Optional. Whether the video should be viewonce. Defaults to False.
    :type viewonce: bool, optional
    :param gifplayback: Optional. Whether the video should be sent as gif. Defaults to False.
    :type gifplayback: bool, optional
    :param is_gif: Optional. Whether the video to be sent is a gif. Defaults to False.
    :type is_gif: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :param add_msg_secret: Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A function for handling the result of the video sending process.
    :rtype: SendResponse
    """
    return self.send_message(
        to,
        self.build_video_message(
            file,
            caption,
            quoted,
            viewonce,
            gifplayback,
            is_gif,
            ghost_mentions,
            mentions_are_lids,
        ),
        add_msg_secret=add_msg_secret,
    )

build_image_message

Python
build_image_message(file: str | bytes, caption: Optional[str] = None, quoted: Optional[Message] = None, viewonce: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False) -> Message

This function builds an image message. It takes a file (either a string or bytes), an optional caption, an optional quoted message, and a boolean indicating whether the message should be viewed once. It then uploads the image, generates a thumbnail, and constructs the message with the given parameters and the information from the uploaded image.

PARAMETER DESCRIPTION
file

The image file to be uploaded and sent, either as a string URL or bytes.

TYPE: str | bytes

caption

The caption for the image message, defaults to None.

TYPE: Optional[str] DEFAULT: None

quoted

The message to be quoted in the image message, defaults to None.

TYPE: Optional[Message] DEFAULT: None

viewonce

Whether the image message should be viewable only once, defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Message

The constructed image message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_image_message(
    self,
    file: str | bytes,
    caption: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    viewonce: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
) -> Message:
    """
    This function builds an image message. It takes a file (either a string or bytes),
    an optional caption, an optional quoted message, and a boolean indicating whether
    the message should be viewed once. It then uploads the image, generates a thumbnail,
    and constructs the message with the given parameters and the information from the
    uploaded image.

    :param file: The image file to be uploaded and sent, either as a string URL or bytes.
    :type file: str | bytes
    :param caption: The caption for the image message, defaults to None.
    :type caption: Optional[str], optional
    :param quoted: The message to be quoted in the image message, defaults to None.
    :type quoted: Optional[neonize_proto.Message], optional
    :param viewonce: Whether the image message should be viewable only once, defaults to False.
    :type viewonce: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :return: The constructed image message.
    :rtype: Message
    """
    n_file = get_bytes_from_name_or_url(file)
    img = Image.open(BytesIO(n_file))
    img.thumbnail(AspectRatioMethod(*img.size, res=200))
    thumbnail = BytesIO()
    img_saveable = img if img.mode == "RGB" else img.convert("RGB")
    img_saveable.save(thumbnail, format="jpeg")
    upload = self.upload(n_file)
    message = Message(
        imageMessage=ImageMessage(
            URL=upload.url,
            caption=caption,
            directPath=upload.DirectPath,
            fileEncSHA256=upload.FileEncSHA256,
            fileLength=upload.FileLength,
            fileSHA256=upload.FileSHA256,
            mediaKey=upload.MediaKey,
            mimetype=magic.from_buffer(n_file, mime=True),
            JPEGThumbnail=thumbnail.getvalue(),
            thumbnailDirectPath=upload.DirectPath,
            thumbnailEncSHA256=upload.FileEncSHA256,
            thumbnailSHA256=upload.FileSHA256,
            viewOnce=viewonce,
            contextInfo=ContextInfo(
                mentionedJID=self._parse_mention(
                    (ghost_mentions or caption), mentions_are_lids
                ),
                groupMentions=(self._parse_group_mention(caption)),
            ),
        )
    )
    if quoted:
        message.imageMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return message

send_image

Python
send_image(to: JID, file: str | bytes, caption: Optional[str] = None, quoted: Optional[Message] = None, viewonce: bool = False, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> SendResponse

Sends an image to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

file

Either a file path (str), url (str) or binary data (bytes) representing the image.

TYPE: str | bytes

caption

Optional. The caption of the image. Defaults to None.

TYPE: Optional[str] DEFAULT: None

quoted

Optional. The message to which the image is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

viewonce

Optional. Whether the image should be viewonce. Defaults to False.

TYPE: bool DEFAULT: False

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

A function for handling the result of the image sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_image(
    self,
    to: JID,
    file: str | bytes,
    caption: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    viewonce: bool = False,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Sends an image to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param file: Either a file path (str), url (str) or binary data (bytes) representing the image.
    :type file: typing.Union[str | bytes]
    :param caption: Optional. The caption of the image. Defaults to None.
    :type caption: Optional[str], optional
    :param quoted: Optional. The message to which the image is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :param viewonce: Optional. Whether the image should be viewonce. Defaults to False.
    :type viewonce: bool, optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :param add_msg_secret: Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A function for handling the result of the image sending process.
    :rtype: SendResponse
    """
    return self.send_message(
        to,
        self.build_image_message(
            file,
            caption,
            quoted,
            viewonce=viewonce,
            ghost_mentions=ghost_mentions,
            mentions_are_lids=mentions_are_lids,
        ),
        add_msg_secret=add_msg_secret,
    )

send_album

Python
send_album(to: JID, files: list, caption: Optional[str] = None, quoted: Optional[Message] = None, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> List[SendResponse, List[SendResponse]]

Sends an album containing images, videos or both to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

files

A list containing either a file path (str), url (str) or binary data (bytes) representing the image/video.

TYPE: list

caption

Optional. The caption of the first media in the album. Defaults to None.

TYPE: Optional[str] DEFAULT: None

quoted

Optional. The message to which the album is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

add_msg_secret

Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
List[SendResponse, List[SendResponse]]

A function for handling the result of the album sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_album(
    self,
    to: JID,
    files: list,
    caption: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> List[SendResponse, List[SendResponse]]:
    """Sends an album containing images, videos or both to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param files: A list containing either a file path (str), url (str) or binary data (bytes) representing the image/video.
    :type file: List[typing.Union[str | bytes]]
    :param caption: Optional. The caption of the first media in the album. Defaults to None.
    :type caption: Optional[str], optional
    :param quoted: Optional. The message to which the album is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param add_msg_secret: Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A function for handling the result of the album sending process.
    :rtype: List[SendResponse, List[SendResponse]]
    """
    image_count = video_count = 0
    medias = []
    for file in files:
        file = get_bytes_from_name_or_url(file)
        mime = magic.from_buffer(file, mime=True)
        media_type = mime.split("/")[0]
        if media_type == "image":
            image_count += 1
        elif media_type == "video":
            video_count += 1
        else:
            _log_.warning(
                f"File with mime_type: {mime} was wrongly passed to send_album_message, ignoring…"
            )
            continue
        medias.append((file, media_type))
    if not (image_count or video_count):
        raise SendMessageError("No media found to send!")
    elif len(medias) < 2:
        raise SendMessageError("No enough media to send an album")
    message = Message(
        albumMessage=AlbumMessage(
            expectedImageCount=image_count,
            expectedVideoCount=video_count,
            contextInfo=ContextInfo(
                mentionedJID=self._parse_mention(
                    (ghost_mentions or caption), mentions_are_lids
                ),
                groupMentions=(self._parse_group_mention(caption)),
            ),
        )
    )
    if quoted:
        message.albumMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    response = self.send_message(to, message, add_msg_secret=add_msg_secret)
    msg_association = MessageAssociation(
        associationType=MessageAssociation.AssociationType.MEDIA_ALBUM,
        parentMessageKey=MessageKey(
            remoteJID=Jid2String(to),
            fromMe=True,
            ID=response.ID,
        ),
    )
    with ThreadPoolExecutor(max_workers=25) as executor:
        futures = [
            executor.submit(
                self.build_album_content,
                file,
                media_type,
                msg_association,
                caption=caption,
                quoted=quoted,
                ghost_mentions=ghost_mentions,
                mentions_are_lids=mentions_are_lids,
            )
            for file, media_type in medias[:1]
        ]
        futures.extend(
            [
                executor.submit(
                    self.build_album_content,
                    file,
                    media_type,
                    msg_association,
                    quoted=quoted,
                )
                for file, media_type in medias[1:]
            ]
        )

        messages = [fut.result() for fut in futures]

    with ThreadPoolExecutor(max_workers=25) as executor:
        send_futures = [
            executor.submit(
                self.send_message, to, msg, add_msg_secret=add_msg_secret
            )
            for msg in messages
        ]
        responses = [fut.result() for fut in send_futures]
    return [response, responses]

build_audio_message

Python
build_audio_message(file: str | bytes, ptt: bool = False, quoted: Optional[Message] = None) -> Message

This method builds an audio message from a given file or bytes.

PARAMETER DESCRIPTION
file

The audio file in string or bytes format to be converted into an audio message

TYPE: str | bytes

ptt

A boolean indicating if the audio message is a 'push to talk' message, defaults to False

TYPE: bool DEFAULT: False

quoted

A message that the audio message may be replying to, defaults to None

TYPE: Optional[Message] DEFAULT: None

RETURNS DESCRIPTION
Message

The audio message built from the given parameters

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def build_audio_message(
    self,
    file: str | bytes,
    ptt: bool = False,
    quoted: Optional[neonize_proto.Message] = None,
) -> Message:
    """
    This method builds an audio message from a given file or bytes.

    :param file: The audio file in string or bytes format to be converted into an audio message
    :type file: str | bytes
    :param ptt: A boolean indicating if the audio message is a 'push to talk' message, defaults to False
    :type ptt: bool, optional
    :param quoted: A message that the audio message may be replying to, defaults to None
    :type quoted: Optional[neonize_proto.Message], optional
    :return: The audio message built from the given parameters
    :rtype: Message
    """
    io = BytesIO(get_bytes_from_name_or_url(file))
    io.seek(0)
    buff = io.read()
    upload = self.upload(buff)
    with FFmpeg(io.getvalue()) as ffmpeg:
        duration = int(ffmpeg.extract_info().format.duration)
    message = Message(
        audioMessage=AudioMessage(
            URL=upload.url,
            seconds=duration,
            directPath=upload.DirectPath,
            fileEncSHA256=upload.FileEncSHA256,
            fileLength=upload.FileLength,
            fileSHA256=upload.FileSHA256,
            mediaKey=upload.MediaKey,
            mimetype=magic.from_buffer(buff, mime=True),
            PTT=ptt,
        )
    )
    if quoted:
        message.audioMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return message

send_audio

Python
send_audio(to: JID, file: str | bytes, ptt: bool = False, quoted: Optional[Message] = None, add_msg_secret: bool = False) -> SendResponse

Sends an audio to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

file

Either a file path (str), url (str) or binary data (bytes) representing the audio.

TYPE: str | bytes

ptt

Optional. Whether the audio should be ptt. Defaults to False.

TYPE: bool DEFAULT: False

quoted

Optional. The message to which the audio is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

add_msg_secret

Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

A function for handling the result of the audio sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_audio(
    self,
    to: JID,
    file: str | bytes,
    ptt: bool = False,
    quoted: Optional[neonize_proto.Message] = None,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Sends an audio to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param file: Either a file path (str), url (str) or binary data (bytes) representing the audio.
    :type file: typing.Union[str | bytes]
    :param ptt: Optional. Whether the audio should be ptt. Defaults to False.
    :type ptt: bool, optional
    :param quoted: Optional. The message to which the audio is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :param add_msg_secret: Optional. Whether to  generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A function for handling the result of the audio sending process.
    :rtype: SendResponse
    """

    return self.send_message(
        to,
        self.build_audio_message(file, ptt, quoted),
        add_msg_secret=add_msg_secret,
    )

send_document

Python
send_document(to: JID, file: str | bytes, caption: Optional[str] = None, title: Optional[str] = None, filename: Optional[str] = None, mimetype: Optional[str] = None, quoted: Optional[Message] = None, ghost_mentions: Optional[str] = None, mentions_are_lids: bool = False, add_msg_secret: bool = False) -> SendResponse

Sends a document to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

file

Either a file path (str), url (str) or binary data (bytes) representing the document.

TYPE: str | bytes

caption

Optional. The caption of the document. Defaults to None.

TYPE: Optional[str] DEFAULT: None

title

Optional. The title of the document. Defaults to None.

TYPE: Optional[str] DEFAULT: None

filename

Optional. The filename of the document. Defaults to None.

TYPE: Optional[str] DEFAULT: None

quoted

Optional. The message to which the document is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

ghost_mentions

List of users to tag silently (Takes precedence over auto detected mentions)

TYPE: Optional[str] DEFAULT: None

mentions_are_lids

whether mentions contained in message or ghost_mentions are lids, defaults to False.

TYPE: bool DEFAULT: False

add_msg_secret

Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
SendResponse

A function for handling the result of the document sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_document(
    self,
    to: JID,
    file: str | bytes,
    caption: Optional[str] = None,
    title: Optional[str] = None,
    filename: Optional[str] = None,
    mimetype: Optional[str] = None,
    quoted: Optional[neonize_proto.Message] = None,
    ghost_mentions: Optional[str] = None,
    mentions_are_lids: bool = False,
    add_msg_secret: bool = False,
) -> SendResponse:
    """Sends a document to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param file: Either a file path (str), url (str) or binary data (bytes) representing the document.
    :type file: typing.Union[str | bytes]
    :param caption: Optional. The caption of the document. Defaults to None.
    :type caption: Optional[str], optional
    :param title: Optional. The title of the document. Defaults to None.
    :type title: Optional[str], optional
    :param filename: Optional. The filename of the document. Defaults to None.
    :type filename: Optional[str], optional
    :param quoted: Optional. The message to which the document is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :param ghost_mentions: List of users to tag silently (Takes precedence over auto detected mentions)
    :type ghost_mentions: str, optional
    :param mentions_are_lids: whether mentions contained in message or ghost_mentions are lids, defaults to False.
    :type mentions_are_lids: bool, optional
    :param add_msg_secret: Optional. Whether to generate 32 random bytes for messageSecret inside MessageContextInfo before sending, defaults to False
    :type add_msg_secret: bool, optional
    :return: A function for handling the result of the document sending process.
    :rtype: SendResponse
    """
    return self.send_message(
        to,
        self.build_document_message(
            file,
            caption,
            title,
            filename,
            mimetype,
            quoted,
            ghost_mentions,
            mentions_are_lids,
        ),
        add_msg_secret=add_msg_secret,
    )

send_contact

Python
send_contact(to: JID, contact_name: str, contact_number: str, quoted: Optional[Message] = None) -> SendResponse

Sends a contact to the specified recipient.

PARAMETER DESCRIPTION
to

The JID (Jabber Identifier) of the recipient.

TYPE: JID

contact_name

The name of the contact.

TYPE: str

contact_number

The number of the contact.

TYPE: str

quoted

Optional. The message to which the contact is a reply. Defaults to None.

TYPE: Optional[Message] DEFAULT: None

RETURNS DESCRIPTION
SendResponse

A function for handling the result of the contact sending process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_contact(
    self,
    to: JID,
    contact_name: str,
    contact_number: str,
    quoted: Optional[neonize_proto.Message] = None,
) -> SendResponse:
    """Sends a contact to the specified recipient.

    :param to: The JID (Jabber Identifier) of the recipient.
    :type to: JID
    :param contact_name: The name of the contact.
    :type contact_name: str
    :param contact_number: The number of the contact.
    :type contact_number: str
    :param quoted: Optional. The message to which the contact is a reply. Defaults to None.
    :type quoted: Optional[Message], optional
    :return: A function for handling the result of the contact sending process.
    :rtype: SendResponse
    """
    message = Message(
        contactMessage=ContactMessage(
            displayName=contact_name,
            vcard=gen_vcard(contact_name, contact_number),
        )
    )
    if quoted:
        message.contactMessage.contextInfo.MergeFrom(
            self._make_quoted_message(quoted)
        )
    return self.send_message(to, message)

upload

Python
upload(binary: bytes, media_type: Optional[MediaType] = None) -> UploadResponse

Uploads media content.

PARAMETER DESCRIPTION
binary

The binary data to be uploaded.

TYPE: bytes

media_type

Optional. The media type of the binary data, defaults to None.

TYPE: Optional[MediaType] DEFAULT: None

RETURNS DESCRIPTION
UploadResponse

An UploadResponse containing information about the upload.

RAISES DESCRIPTION
UploadError

Raised if there is an issue with the upload.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def upload(
    self, binary: bytes, media_type: Optional[MediaType] = None
) -> UploadResponse:
    """Uploads media content.

    :param binary: The binary data to be uploaded.
    :type binary: bytes
    :param media_type: Optional. The media type of the binary data, defaults to None.
    :type media_type: Optional[MediaType], optional
    :raises UploadError: Raised if there is an issue with the upload.
    :return: An UploadResponse containing information about the upload.
    :rtype: UploadResponse
    """
    if not media_type:
        mime = MediaType.from_magic(binary)
    else:
        mime = media_type
    bytes_ptr = self.__client.Upload(self.uuid, binary, len(binary), mime.value)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    upload_model = UploadReturnFunction.FromString(protobytes)
    if upload_model.Error:
        raise UploadError(upload_model.Error)
    return upload_model.UploadResponse

download_any

Python
download_any(message: Message) -> bytes
Python
download_any(message: Message, path: str) -> NoneType
Python
download_any(message: Message, path: Optional[str] = None) -> typing.Union[None, bytes]

Downloads content from a message.

PARAMETER DESCRIPTION
message

The message containing the content to download.

TYPE: Message

path

Optional. The local path to save the downloaded content, defaults to None.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Union[None, bytes]

The downloaded content as bytes, or None if the content is not available.

RAISES DESCRIPTION
DownloadException

Raised if there is an issue with the download.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def download_any(
    self, message: Message, path: Optional[str] = None
) -> typing.Union[None, bytes]:
    """Downloads content from a message.

    :param message: The message containing the content to download.
    :type message: Message
    :param path: Optional. The local path to save the downloaded content, defaults to None.
    :type path: Optional[str], optional
    :raises DownloadException: Raised if there is an issue with the download.
    :return: The downloaded content as bytes, or None if the content is not available.
    :rtype: Union[None, bytes]
    """
    msg_protobuf = message.SerializeToString()
    bytes_ptr = self.__client.DownloadAny(
        self.uuid, msg_protobuf, len(msg_protobuf)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    media = DownloadReturnFunction.FromString(protobytes)
    if media.Error:
        raise DownloadError(media.Error)
    if path:
        with open(path, "wb") as file:
            file.write(media.Binary)
    else:
        return media.Binary
    return None

download_media_with_path

Python
download_media_with_path(direct_path: str, enc_file_hash: bytes, file_hash: bytes, media_key: bytes, file_length: int, media_type: MediaType, mms_type: MediaTypeToMMS) -> bytes

Downloads media with the given parameters and path. The media is downloaded from the path specified.

PARAMETER DESCRIPTION
direct_path

The direct path to the media to be downloaded.

TYPE: str

enc_file_hash

The encrypted hash of the file.

TYPE: bytes

file_hash

The hash of the file.

TYPE: bytes

media_key

The key of the media to be downloaded.

TYPE: bytes

file_length

The length of the file to be downloaded.

TYPE: int

media_type

The type of the media to be downloaded.

TYPE: MediaType

mms_type

The type of the MMS to be downloaded.

TYPE: MediaTypeToMMS

RETURNS DESCRIPTION
bytes

The downloaded media in bytes.

RAISES DESCRIPTION
DownloadError

If there is an error in the download process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def download_media_with_path(
    self,
    direct_path: str,
    enc_file_hash: bytes,
    file_hash: bytes,
    media_key: bytes,
    file_length: int,
    media_type: MediaType,
    mms_type: MediaTypeToMMS,
) -> bytes:
    """
    Downloads media with the given parameters and path. The media is downloaded from the path specified.

    :param direct_path: The direct path to the media to be downloaded.
    :type direct_path: str
    :param enc_file_hash: The encrypted hash of the file.
    :type enc_file_hash: bytes
    :param file_hash: The hash of the file.
    :type file_hash: bytes
    :param media_key: The key of the media to be downloaded.
    :type media_key: bytes
    :param file_length: The length of the file to be downloaded.
    :type file_length: int
    :param media_type: The type of the media to be downloaded.
    :type media_type: MediaType
    :param mms_type: The type of the MMS to be downloaded.
    :type mms_type: str
    :raises DownloadError: If there is an error in the download process.
    :return: The downloaded media in bytes.
    :rtype: bytes
    """
    bytes_ptr = self.__client.DownloadMediaWithPath(
        self.uuid,
        direct_path.encode(),
        enc_file_hash,
        len(enc_file_hash),
        file_hash,
        len(file_hash),
        media_key,
        len(media_key),
        file_length,
        media_type.value,
        mms_type.value.encode(),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.DownloadReturnFunction.FromString(protobytes)
    if model.Error:
        raise DownloadError(model.Error)
    return model.Binary

generate_message_id

Python
generate_message_id() -> str

Generates a unique identifier for a message.

RETURNS DESCRIPTION
str

A string representing the unique identifier for the message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def generate_message_id(self) -> str:
    """Generates a unique identifier for a message.

    :return: A string representing the unique identifier for the message.
    :rtype: str
    """
    return self.__client.GenerateMessageID(self.uuid).decode()

send_chat_presence

Python
send_chat_presence(jid: JID, state: ChatPresence, media: ChatPresenceMedia) -> str

Sends chat presence information.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the chat.

TYPE: JID

state

The chat presence state.

TYPE: ChatPresence

media

The chat presence media information.

TYPE: ChatPresenceMedia

RETURNS DESCRIPTION
str

A string indicating the result or status of the presence information sending.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_chat_presence(
    self, jid: JID, state: ChatPresence, media: ChatPresenceMedia
) -> str:
    """Sends chat presence information.

    :param jid: The JID (Jabber Identifier) of the chat.
    :type jid: JID
    :param state: The chat presence state.
    :type state: ChatPresence
    :param media: The chat presence media information.
    :type media: ChatPresenceMedia
    :return: A string indicating the result or status of the presence information sending.
    :rtype: str
    """
    jidbyte = jid.SerializeToString()
    return self.__client.SendChatPresence(
        self.uuid, jidbyte, len(jidbyte), state.value, media.value
    ).decode()

is_on_whatsapp

Python
is_on_whatsapp(*numbers: str) -> Sequence[IsOnWhatsAppResponse]

This function checks if the provided phone numbers are registered with WhatsApp.

PARAMETER DESCRIPTION
numbers

A series of phone numbers to be checked.

TYPE: str DEFAULT: ()

RETURNS DESCRIPTION
Sequence[IsOnWhatsAppResponse]

A list of responses, each indicating whether the corresponding number is registered with WhatsApp.

RAISES DESCRIPTION
IsOnWhatsAppError

If an error occurs while verifying the phone numbers.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def is_on_whatsapp(self, *numbers: str) -> Sequence[IsOnWhatsAppResponse]:
    """
    This function checks if the provided phone numbers are registered with WhatsApp.

    :param numbers: A series of phone numbers to be checked.
    :type numbers: str
    :raises IsOnWhatsAppError: If an error occurs while verifying the phone numbers.
    :return: A list of responses, each indicating whether the corresponding number is registered with WhatsApp.
    :rtype: Sequence[IsOnWhatsAppResponse]
    """
    if numbers:
        numbers_buf = " ".join(numbers).encode()
        bytes_ptr = self.__client.IsOnWhatsApp(
            self.uuid, numbers_buf, len(numbers_buf)
        )
        protobytes = bytes_ptr.contents.get_bytes()
        free_bytes(bytes_ptr)
        model = IsOnWhatsAppReturnFunction.FromString(protobytes)
        if model.Error:
            raise IsOnWhatsAppError(model.Error)
        return model.IsOnWhatsAppResponse
    return []

get_user_info

Python
get_user_info(*jid: JID) -> RepeatedCompositeFieldContainer[GetUserInfoSingleReturnFunction]

This function retrieves user information given a set of JID. It serializes the JID into a string, gets the user information from the client, deserializes the returned information, checks for any errors, and finally returns the user information.

PARAMETER DESCRIPTION
jid

JID of the users to retrieve information from

TYPE: JID DEFAULT: ()

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[GetUserInfoSingleReturnFunction]

The user information for each JID

RAISES DESCRIPTION
GetUserInfoError

If there is an error in the model returned by the client

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_user_info(
    self, *jid: JID
) -> RepeatedCompositeFieldContainer[GetUserInfoSingleReturnFunction]:
    """
    This function retrieves user information given a set of JID. It serializes the JID into a string,
    gets the user information from the client, deserializes the returned information, checks for any errors,
    and finally returns the user information.

    :param jid: JID of the users to retrieve information from
    :type jid: JID
    :raises GetUserInfoError: If there is an error in the model returned by the client
    :return: The user information for each JID
    :rtype: RepeatedCompositeFieldContainer[GetUserInfoSingleReturnFunction]
    """
    jidbuf = JIDArray(JIDS=jid).SerializeToString()
    bytes_ptr = self.__client.GetUserInfo(self.uuid, jidbuf, len(jidbuf))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetUserInfoReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetUserInfoError(model.Error)
    return model.UsersInfo

get_group_info

Python
get_group_info(jid: JID) -> GroupInfo

Retrieves information about a group.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the group.

TYPE: JID

RETURNS DESCRIPTION
GroupInfo

Information about the specified group.

RAISES DESCRIPTION
GetGroupInfoError

Raised if there is an issue retrieving group information.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_group_info(self, jid: JID) -> GroupInfo:
    """Retrieves information about a group.

    :param jid: The JID (Jabber Identifier) of the group.
    :type jid: JID
    :raises GetGroupInfoError: Raised if there is an issue retrieving group information.
    :return: Information about the specified group.
    :rtype: GroupInfo
    """
    jidbuf = jid.SerializeToString()
    bytes_ptr = self.__client.GetGroupInfo(
        self.uuid,
        jidbuf,
        len(jidbuf),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetGroupInfoReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetGroupInfoError(model.Error)
    return model.GroupInfo
Python
get_group_info_from_link(code: str) -> GroupInfo

Retrieves group information from a given link.

PARAMETER DESCRIPTION
code

The link code.

TYPE: str

RETURNS DESCRIPTION
GroupInfo

An object containing the group information.

RAISES DESCRIPTION
GetGroupInfoError

If there is an error retrieving the group information.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_group_info_from_link(self, code: str) -> GroupInfo:
    """Retrieves group information from a given link.

    :param code: The link code.
    :type code: str
    :return: An object containing the group information.
    :rtype: GroupInfo
    :raises GetGroupInfoError: If there is an error retrieving the group information.
    """
    bytes_ptr = self.__client.GetGroupInfoFromLink(self.uuid, code.encode())
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetGroupInfoReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetGroupInfoError(model.Error)
    return model.GroupInfo

get_group_info_from_invite

Python
get_group_info_from_invite(jid: JID, inviter: JID, code: str, expiration: int) -> GroupInfo

Retrieves group information from an invite.

PARAMETER DESCRIPTION
jid

The JID (Jabber ID) of the group.

TYPE: JID

inviter

The JID of the user who sent the invite.

TYPE: JID

code

The invite code.

TYPE: str

expiration

The expiration time of the invite.

TYPE: int

RETURNS DESCRIPTION
GroupInfo

The group information.

RAISES DESCRIPTION
GetGroupInfoError

If there is an error retrieving the group information.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_group_info_from_invite(
    self, jid: JID, inviter: JID, code: str, expiration: int
) -> GroupInfo:
    """Retrieves group information from an invite.

    :param jid: The JID (Jabber ID) of the group.
    :type jid: JID
    :param inviter: The JID of the user who sent the invite.
    :type inviter: JID
    :param code: The invite code.
    :type code: str
    :param expiration: The expiration time of the invite.
    :type expiration: int

    :return: The group information.
    :rtype: GroupInfo

    :raises GetGroupInfoError: If there is an error retrieving the group information.
    """
    jidbyte = jid.SerializeToString()
    inviterbyte = inviter.SerializeToString()
    bytes_ptr = self.__client.GetGroupInfoFromInvite(
        self.uuid,
        jidbyte,
        len(jidbyte),
        inviterbyte,
        len(inviterbyte),
        code.encode(),
        expiration,
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetGroupInfoReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetGroupInfoError(model.Error)
    return model.GroupInfo

set_group_name

Python
set_group_name(jid: JID, name: str) -> str

Sets the name of a group.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the group.

TYPE: JID

name

The new name to be set for the group.

TYPE: str

RETURNS DESCRIPTION
str

A string indicating the result or an error status. Empty string if successful.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_group_name(self, jid: JID, name: str) -> str:
    """Sets the name of a group.

    :param jid: The JID (Jabber Identifier) of the group.
    :type jid: JID
    :param name: The new name to be set for the group.
    :type name: str
    :return: A string indicating the result or an error status. Empty string if successful.
    :rtype: str
    """
    jidbuf = jid.SerializeToString()
    return self.__client.SetGroupName(
        self.uuid, jidbuf, len(jidbuf), ctypes.create_string_buffer(name.encode())
    ).decode()

set_group_photo

Python
set_group_photo(jid: JID, file_or_bytes: Union[str, bytes]) -> str

Sets the photo of a group.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the group.

TYPE: JID

file_or_bytes

Either a file path (str) or binary data (bytes) representing the group photo.

TYPE: Union[str, bytes]

RETURNS DESCRIPTION
str

A string indicating the result or an error status.

RAISES DESCRIPTION
SetGroupPhotoError

Raised if there is an issue setting the group photo.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_group_photo(self, jid: JID, file_or_bytes: typing.Union[str, bytes]) -> str:
    """Sets the photo of a group.

    :param jid: The JID (Jabber Identifier) of the group.
    :type jid: JID
    :param file_or_bytes: Either a file path (str) or binary data (bytes) representing the group photo.
    :type file_or_bytes: typing.Union[str, bytes]
    :raises SetGroupPhotoError: Raised if there is an issue setting the group photo.
    :return: A string indicating the result or an error status.
    :rtype: str
    """
    data = get_bytes_from_name_or_url(file_or_bytes)
    jid_buf = jid.SerializeToString()
    bytes_ptr = self.__client.SetGroupPhoto(
        self.uuid, jid_buf, len(jid_buf), data, len(data)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = SetGroupPhotoReturnFunction.FromString(protobytes)
    if model.Error:
        raise SetGroupPhotoError(model.Error)
    return model.PictureID

set_profile_photo

Python
set_profile_photo(file_or_bytes: Union[str, bytes]) -> str

Sets profile photo.

PARAMETER DESCRIPTION
file_or_bytes

Either a file path (str) or binary data (bytes) representing the group photo.

TYPE: Union[str, bytes]

RETURNS DESCRIPTION
str

A string indicating the result or an error status.

RAISES DESCRIPTION
SetGroupPhotoError

Raised if there is an issue setting the profile photo.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_profile_photo(self, file_or_bytes: typing.Union[str, bytes]) -> str:
    """Sets profile photo.

    :param file_or_bytes: Either a file path (str) or binary data (bytes) representing the group photo.
    :type file_or_bytes: typing.Union[str, bytes]
    :raises SetGroupPhotoError: Raised if there is an issue setting the profile photo.
    :return: A string indicating the result or an error status.
    :rtype: str
    """
    data = get_bytes_from_name_or_url(file_or_bytes)
    bytes_ptr = self.__client.SetProfilePhoto(self.uuid, data, len(data))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = SetGroupPhotoReturnFunction.FromString(protobytes)
    if model.Error:
        raise SetGroupPhotoError(model.Error)
    return model.PictureID

get_lid_from_pn

Python
get_lid_from_pn(jid: JID) -> JID

Retrieves the matching lid from the supplied jid.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) (pn) of the target user.

TYPE: JID

RETURNS DESCRIPTION
JID

The lid (hidden user) matching the supplied jid.

RAISES DESCRIPTION
GetJIDFromStoreError

Raised if there is an issue getting the lid from the given jid.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_lid_from_pn(self, jid: JID) -> JID:
    """Retrieves the matching lid from the supplied jid.

    :param jid: The JID (Jabber Identifier) (pn) of the target user.
    :type jid: JID
    :raises GetJIDFromStoreError: Raised if there is an issue getting the lid from the given jid.
    :return: The lid (hidden user) matching the supplied jid.
    :rtype: JID
    """
    jid_buf = jid.SerializeToString()
    bytes_ptr = self.__client.GetLIDFromPN(self.uuid, jid_buf, len(jid_buf))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetJIDFromStoreReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetJIDFromStoreError(model.Error)
    return model.Jid

get_pn_from_lid

Python
get_pn_from_lid(jid: JID) -> JID

Retrieves the matching jid from the supplied lid.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) (lid) of the target user.

TYPE: JID

RETURNS DESCRIPTION
JID

The jid (phone number) matching the supplied lid.

RAISES DESCRIPTION
GetJIDFromStoreError

Raised if there is an issue getting the jid from the given lid.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_pn_from_lid(self, jid: JID) -> JID:
    """Retrieves the matching jid from the supplied lid.

    :param jid: The JID (Jabber Identifier) (lid) of the target user.
    :type jid: JID
    :raises GetJIDFromStoreError: Raised if there is an issue getting the jid from the given lid.
    :return: The jid (phone number) matching the supplied lid.
    :rtype: JID
    """
    jid_buf = jid.SerializeToString()
    bytes_ptr = self.__client.GetPNFromLID(self.uuid, jid_buf, len(jid_buf))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetJIDFromStoreReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetJIDFromStoreError(model.Error)
    return model.Jid

pin_message

Python
pin_message(chat_jid: JID, sender_jid: JID, message_id: str, seconds: int)

Currently Non-functional

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def pin_message(
    self, chat_jid: JID, sender_jid: JID, message_id: str, seconds: int
):
    """
    Currently Non-functional
    """
    chat_buf = chat_jid.SerializeToString()
    sender_buf = sender_jid.SerializeToString()
    bytes_ptr = self.__client.PinMessage(
        self.uuid,
        chat_buf,
        len(chat_buf),
        sender_buf,
        len(sender_buf),
        message_id.encode(),
        seconds,
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = SendMessageReturnFunction.FromString(protobytes)
    if model.Error:
        raise SendMessageError(model.Error)
    return model.SendResponse

leave_group

Python
leave_group(jid: JID) -> str

Leaves a group.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the target group.

TYPE: JID

RETURNS DESCRIPTION
str

A string indicating the result or an error status. Empty string if successful.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def leave_group(self, jid: JID) -> str:
    """Leaves a group.

    :param jid: The JID (Jabber Identifier) of the target group.
    :type jid: JID
    :return: A string indicating the result or an error status. Empty string if successful.
    :rtype: str
    """
    jid_buf = jid.SerializeToString()
    return self.__client.LeaveGroup(self.uuid, jid_buf, len(jid_buf)).decode()
Python
get_group_invite_link(jid: JID, revoke: bool = False) -> str

Gets or revokes the invite link for a group.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the group.

TYPE: JID

revoke

Optional. If True, revokes the existing invite link; if False, gets the invite link. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

The group invite link or an error status.

RAISES DESCRIPTION
GetGroupInviteLinkError

Raised if there is an issue getting or revoking the invite link.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_group_invite_link(self, jid: JID, revoke: bool = False) -> str:
    """Gets or revokes the invite link for a group.

    :param jid: The JID (Jabber Identifier) of the group.
    :type jid: JID
    :param revoke: Optional. If True, revokes the existing invite link; if False, gets the invite link. Defaults to False.
    :type revoke: bool, optional
    :raises GetGroupInviteLinkError: Raised if there is an issue getting or revoking the invite link.
    :return: The group invite link or an error status.
    :rtype: str
    """
    jid_buf = jid.SerializeToString()
    bytes_ptr = self.__client.GetGroupInviteLink(
        self.uuid, jid_buf, len(jid_buf), revoke
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetGroupInviteLinkReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetGroupInviteLinkError(model.Error)
    return model.InviteLink
Python
join_group_with_link(code: str) -> JID

Join a group using an invite link.

PARAMETER DESCRIPTION
code

The invite code or link for joining the group.

TYPE: str

RETURNS DESCRIPTION
JID

The JID (Jabber Identifier) of the joined group.

RAISES DESCRIPTION
InviteLinkError

Raised if the group membership is pending approval or if the link is invalid.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def join_group_with_link(self, code: str) -> JID:
    """Join a group using an invite link.

    :param code: The invite code or link for joining the group.
    :type code: str
    :raises InviteLinkError: Raised if the group membership is pending approval or if the link is invalid.
    :return: The JID (Jabber Identifier) of the joined group.
    :rtype: JID
    """
    bytes_ptr = self.__client.JoinGroupWithLink(self.uuid, code.encode())
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = JoinGroupWithLinkReturnFunction.FromString(protobytes)
    if model.Error:
        raise InviteLinkError(model.Error)
    return model.Jid

join_group_with_invite

Python
join_group_with_invite(jid: JID, inviter: JID, code: str, expiration: int)

This function allows a user to join a group in a chat application using an invite. It uses the JID (Jabber ID) of the group, the JID of the inviter, an invitation code, and an expiration time for the code.

PARAMETER DESCRIPTION
jid

The JID of the group to join.

TYPE: JID

inviter

The JID of the person who sent the invite.

TYPE: JID

code

The invitation code.

TYPE: str

expiration

The expiration time of the invitation code.

TYPE: int

RAISES DESCRIPTION
JoinGroupWithInviteError

If there is an error in joining the group, such as an invalid code or expired invitation.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def join_group_with_invite(
    self, jid: JID, inviter: JID, code: str, expiration: int
):
    """
    This function allows a user to join a group in a chat application using an invite.
    It uses the JID (Jabber ID) of the group, the JID of the inviter, an invitation code, and an expiration time for the code.

    :param jid: The JID of the group to join.
    :type jid: JID
    :param inviter: The JID of the person who sent the invite.
    :type inviter: JID
    :param code: The invitation code.
    :type code: str
    :param expiration: The expiration time of the invitation code.
    :type expiration: int
    :raises JoinGroupWithInviteError: If there is an error in joining the group, such as an invalid code or expired invitation.
    """
    jidbytes = jid.SerializeToString()
    inviterbytes = inviter.SerializeToString()
    err = self.__client.JoinGroupWithInvite(
        self.uuid,
        jidbytes,
        len(jidbytes),
        inviterbytes,
        len(inviterbytes),
        code.encode(),
        expiration,
    ).decode()
    if err:
        raise JoinGroupWithInviteError(err)
Python
link_group(parent: JID, child: JID)

Links a child group to a parent group.

PARAMETER DESCRIPTION
parent

The JID of the parent group

TYPE: JID

child

The JID of the child group

TYPE: JID

RAISES DESCRIPTION
LinkGroupError

If there is an error while linking the groups

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def link_group(self, parent: JID, child: JID):
    """
    Links a child group to a parent group.

    :param parent: The JID of the parent group
    :type parent: JID
    :param child: The JID of the child group
    :type child: JID
    :raises LinkGroupError: If there is an error while linking the groups
    """
    parent_bytes = parent.SerializeToString()
    child_bytes = child.SerializeToString()
    err = self.__client.LinkGroup(
        self.uuid, parent_bytes, len(parent_bytes), child_bytes, len(child_bytes)
    ).decode()
    if err:
        raise LinkGroupError(err)

mark_read

Python
mark_read(*message_ids: str, chat: JID, sender: JID, receipt: ReceiptType, timestamp: Optional[int] = None)

Marks the specified messages as read.

PARAMETER DESCRIPTION
message_ids

Identifiers of the messages to mark as read.

TYPE: str DEFAULT: ()

chat

The JID of the chat.

TYPE: JID

sender

The JID of the sender.

TYPE: JID

receipt

The type of receipt indicating the message status.

TYPE: ReceiptType

timestamp

The timestamp of the read action, defaults to None.

TYPE: Optional[int] DEFAULT: None

RAISES DESCRIPTION
MarkReadError

If there is an error marking messages as read.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def mark_read(
    self,
    *message_ids: str,
    chat: JID,
    sender: JID,
    receipt: ReceiptType,
    timestamp: Optional[int] = None,
):
    """Marks the specified messages as read.

    :param message_ids: Identifiers of the messages to mark as read.
    :type message_ids: str
    :param chat: The JID of the chat.
    :type chat: JID
    :param sender: The JID of the sender.
    :type sender: JID
    :param receipt: The type of receipt indicating the message status.
    :type receipt: ReceiptType
    :param timestamp: The timestamp of the read action, defaults to None.
    :type timestamp: Optional[int], optional
    :raises MarkReadError: If there is an error marking messages as read.
    """
    chat_proto = chat.SerializeToString()
    sender_proto = sender.SerializeToString()
    timestamp_args = int(time.time()) if timestamp is None else timestamp
    err = self.__client.MarkRead(
        self.uuid,
        " ".join(message_ids).encode(),
        timestamp_args,
        chat_proto,
        len(chat_proto),
        sender_proto,
        len(sender_proto),
        receipt.value,
    )
    if err:
        raise MarkReadError(err.decode())

newsletter_mark_viewed

Python
newsletter_mark_viewed(jid: JID, message_server_ids: List[MessageServerID])

Marks the specified newsletters as viewed by the user with the given JID.

PARAMETER DESCRIPTION
jid

The JID (Jabber ID) of the user who has viewed the newsletters.

TYPE: JID

message_server_ids

List of server IDs of the newsletters that have been viewed.

TYPE: List[MessageServerID]

RAISES DESCRIPTION
NewsletterMarkViewedError

If an error occurs while marking the newsletters as viewed.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def newsletter_mark_viewed(
    self, jid: JID, message_server_ids: List[MessageServerID]
):
    """
    Marks the specified newsletters as viewed by the user with the given JID.

    :param jid: The JID (Jabber ID) of the user who has viewed the newsletters.
    :type jid: JID
    :param message_server_ids: List of server IDs of the newsletters that have been viewed.
    :type message_server_ids: List[MessageServerID]
    :raises NewsletterMarkViewedError: If an error occurs while marking the newsletters as viewed.
    """
    servers = struct.pack(f"{len(message_server_ids)}b", *message_server_ids)
    jid_proto = jid.SerializeToString()
    err = self.__client.NewsletterMarkViewed(
        self.uuid, jid_proto, len(jid_proto), servers, len(servers)
    )
    if err:
        raise NewsletterMarkViewedError(err)

newsletter_send_reaction

Python
newsletter_send_reaction(jid: JID, message_server_id: MessageServerID, reaction: str, message_id: str)

Sends a reaction to a newsletter.

PARAMETER DESCRIPTION
jid

The unique identifier for the recipient of the newsletter.

TYPE: JID

message_server_id

The unique identifier for the server where the message is stored.

TYPE: MessageServerID

reaction

The reaction to be sent.

TYPE: str

message_id

The unique identifier for the message to which the reaction is being sent.

TYPE: str

RAISES DESCRIPTION
NewsletterSendReactionError

If an error occurs while sending the reaction.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def newsletter_send_reaction(
    self,
    jid: JID,
    message_server_id: MessageServerID,
    reaction: str,
    message_id: str,
):
    """
    Sends a reaction to a newsletter.

    :param jid: The unique identifier for the recipient of the newsletter.
    :type jid: JID
    :param message_server_id: The unique identifier for the server where the message is stored.
    :type message_server_id: MessageServerID
    :param reaction: The reaction to be sent.
    :type reaction: str
    :param message_id: The unique identifier for the message to which the reaction is being sent.
    :type message_id: str
    :raises NewsletterSendReactionError: If an error occurs while sending the reaction.
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.NewsletterSendReaction(
        self.uuid,
        jid_proto,
        len(jid_proto),
        message_server_id,
        reaction.encode(),
        message_id.encode(),
    )
    if err:
        raise NewsletterSendReactionError(err)
    return

newsletter_subscribe_live_updates

Python
newsletter_subscribe_live_updates(jid: JID) -> int

Subscribes a user to live updates of a newsletter.

PARAMETER DESCRIPTION
jid

The unique identifier of the user subscribing to the newsletter.

TYPE: JID

RETURNS DESCRIPTION
int

The duration for which the subscription is valid.

RAISES DESCRIPTION
NewsletterSubscribeLiveUpdatesError

If there is an error during the subscription process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def newsletter_subscribe_live_updates(self, jid: JID) -> int:
    """Subscribes a user to live updates of a newsletter.

    :param jid: The unique identifier of the user subscribing to the newsletter.
    :type jid: JID
    :raises NewsletterSubscribeLiveUpdatesError: If there is an error during the subscription process.
    :return: The duration for which the subscription is valid.
    :rtype: int
    """
    jid_proto = jid.SerializeToString()
    bytes_ptr = self.__client.NewsletterSubscribeLiveUpdates(
        self.uuid, jid_proto, len(jid_proto)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.NewsletterSubscribeLiveUpdatesReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise NewsletterSubscribeLiveUpdatesError(model.Error)
    return model.Duration

newsletter_toggle_mute

Python
newsletter_toggle_mute(jid: JID, mute: bool)

Toggle the mute status of a given JID.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the user.

TYPE: JID

mute

The desired mute status. If True, the user will be muted. If False, the user will be unmuted.

TYPE: bool

RAISES DESCRIPTION
NewsletterToggleMuteError

If there is an error while toggling the mute status.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def newsletter_toggle_mute(self, jid: JID, mute: bool):
    """Toggle the mute status of a given JID.

    :param jid: The JID (Jabber Identifier) of the user.
    :type jid: JID
    :param mute: The desired mute status. If True, the user will be muted. If False, the user will be unmuted.
    :type mute: bool
    :raises NewsletterToggleMuteError: If there is an error while toggling the mute status.
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.NewsletterToggleMute(
        self.uuid, jid_proto, len(jid_proto), mute
    ).decode()
    if err:
        raise NewsletterToggleMuteError(err)
Python
resolve_business_message_link(code: str) -> neonize_proto.BusinessMessageLinkTarget

Resolves the target of a business message link.

PARAMETER DESCRIPTION
code

The code of the business message link to be resolved.

TYPE: str

RETURNS DESCRIPTION
neonize_proto.BusinessMessageLinkTarget

The target of the business message link.

RAISES DESCRIPTION
ResolveContactQRLinkError

If an error occurs while resolving the link.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def resolve_business_message_link(
    self, code: str
) -> neonize_proto.BusinessMessageLinkTarget:
    """Resolves the target of a business message link.

    :param code: The code of the business message link to be resolved.
    :type code: str
    :raises ResolveContactQRLinkError: If an error occurs while resolving the link.
    :return: The target of the business message link.
    :rtype: neonize_proto.BusinessMessageLinkTarget
    """
    bytes_ptr = self.__client.ResolveBusinessMessageLink(self.uuid, code.encode())
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.ResolveBusinessMessageLinkReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise ResolveContactQRLinkError(model.Error)
    return model.MessageLinkTarget
Python
resolve_contact_qr_link(code: str) -> neonize_proto.ContactQRLinkTarget

Resolves a QR link for a specific contact.

PARAMETER DESCRIPTION
code

The QR code to be resolved.

TYPE: str

RETURNS DESCRIPTION
neonize_proto.ContactQRLinkTarget

The target contact of the QR link.

RAISES DESCRIPTION
ResolveContactQRLinkError

If an error occurs while resolving the QR link.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def resolve_contact_qr_link(self, code: str) -> neonize_proto.ContactQRLinkTarget:
    """Resolves a QR link for a specific contact.

    :param code: The QR code to be resolved.
    :type code: str
    :raises ResolveContactQRLinkError: If an error occurs while resolving the QR link.
    :return: The target contact of the QR link.
    :rtype: neonize_proto.ContactQRLinkTarget
    """
    bytes_ptr = self.__client.ResolveContactQRLink(self.uuid, code.encode())
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.ResolveContactQRLinkReturnFunction.FromString(protobytes)
    if model.Error:
        raise ResolveContactQRLinkError(model.Error)
    return model.ContactQrLink

send_app_state

Python
send_app_state(patch_info: PatchInfo)

This function serializes the application state and sends it to the client. If there's an error during this process, it raises a SendAppStateError exception.

PARAMETER DESCRIPTION
patch_info

Contains the information about the application state that needs to be patched.

TYPE: PatchInfo

RAISES DESCRIPTION
SendAppStateError

If there's an error while sending the application state, this exception is raised.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def send_app_state(self, patch_info: neonize_proto.PatchInfo):
    """
    This function serializes the application state and sends it to the client. If there's an error during this process,
    it raises a SendAppStateError exception.

    :param patch_info: Contains the information about the application state that needs to be patched.
    :type patch_info: neonize_proto.PatchInfo
    :raises SendAppStateError: If there's an error while sending the application state, this exception is raised.
    """
    patch = patch_info.SerializeToString()
    err = self.__client.SendAppState(self.uuid, patch, len(patch)).decode()
    if err:
        raise SendAppStateError(err)

set_default_disappearing_timer

Python
set_default_disappearing_timer(timer: Union[timedelta, int])

Sets a default disappearing timer for messages. The timer can be specified as a timedelta or an integer. If a timedelta is provided, it is converted to nanoseconds. If an integer is provided, it is used directly as the timer.

PARAMETER DESCRIPTION
timer

The duration for messages to exist before disappearing. Can be a timedelta or an integer.

TYPE: Union[timedelta, int]

RAISES DESCRIPTION
SetDefaultDisappearingTimerError

If an error occurs while setting the disappearing timer.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_default_disappearing_timer(self, timer: typing.Union[timedelta, int]):
    """
    Sets a default disappearing timer for messages. The timer can be specified as a timedelta or an integer.
    If a timedelta is provided, it is converted to nanoseconds. If an integer is provided, it is used directly as the timer.

    :param timer: The duration for messages to exist before disappearing. Can be a timedelta or an integer.
    :type timer: typing.Union[timedelta, int]
    :raises SetDefaultDisappearingTimerError: If an error occurs while setting the disappearing timer.
    """
    timestamp = 0
    if isinstance(timer, timedelta):
        timestamp = int(timer.total_seconds() * 1000**3)
    else:
        timestamp = timer
    err = self.__client.SetDefaultDisappearingTimer(self.uuid, timestamp).decode()
    if err:
        raise SetDefaultDisappearingTimerError(err)

set_disappearing_timer

Python
set_disappearing_timer(jid: JID, timer: Union[timedelta, int], setting_ts: Optional[timedelta] = None)

Set a disappearing timer for a specific JID. The timer can be set as either a timedelta object or an integer. If a timedelta object is provided, it's converted into nanoseconds. If an integer is provided, it's interpreted as nanoseconds.

PARAMETER DESCRIPTION
jid

The JID for which the disappearing timer is to be set

TYPE: JID

timer

The duration for the disappearing timer. Can be a timedelta object or an integer representing nanoseconds.

TYPE: Union[timedelta, int]

RAISES DESCRIPTION
SetDisappearingTimerError

If there is an error in setting the disappearing timer

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_disappearing_timer(
    self,
    jid: JID,
    timer: typing.Union[timedelta, int],
    setting_ts: Optional[timedelta] = None,
):
    """
    Set a disappearing timer for a specific JID. The timer can be set as either a timedelta object or an integer.
    If a timedelta object is provided, it's converted into nanoseconds. If an integer is provided, it's interpreted as nanoseconds.

    :param jid: The JID for which the disappearing timer is to be set
    :type jid: JID
    :param timer: The duration for the disappearing timer. Can be a timedelta object or an integer representing nanoseconds.
    :type timer: typing.Union[timedelta, int]
    :raises SetDisappearingTimerError: If there is an error in setting the disappearing timer
    """
    timestamp = 0
    jid_proto = jid.SerializeToString()
    if isinstance(timer, timedelta):
        timestamp = int(timer.total_seconds() * 1000)
    else:
        timestamp = timer
    setting_ts_ms = 0
    if setting_ts:
        setting_ts_ms = int(time.time() + setting_ts.total_seconds() * 1000)
    err = self.__client.SetDisappearingTimer(
        self.uuid, jid_proto, len(jid_proto), timestamp, setting_ts_ms
    ).decode()
    if err:
        raise SetDisappearingTimerError(err)

set_force_activate_delivery_receipts

Python
set_force_activate_delivery_receipts(active: bool)

This method is used to forcibly activate or deactivate the delivery receipts for a client.

PARAMETER DESCRIPTION
active

This parameter determines whether the delivery receipts should be forcibly activated or deactivated. If it's True, the delivery receipts will be forcibly activated, otherwise, they will be deactivated.

TYPE: bool

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_force_activate_delivery_receipts(self, active: bool):
    """
    This method is used to forcibly activate or deactivate the delivery receipts for a client.

    :param active: This parameter determines whether the delivery receipts should be forcibly activated or deactivated. If it's True, the delivery receipts will be forcibly activated, otherwise, they will be deactivated.
    :type active: bool
    """
    self.__client.SetForceActiveDeliveryReceipts(self.uuid, active)

set_group_announce

Python
set_group_announce(jid: JID, announce: bool)

Sets the announcement status of a group.

PARAMETER DESCRIPTION
jid

The unique identifier of the group

TYPE: JID

announce

The announcement status to be set. If True, announcements are enabled. If False, they are disabled.

TYPE: bool

RAISES DESCRIPTION
SetGroupAnnounceError

If there is an error while setting the announcement status

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_group_announce(self, jid: JID, announce: bool):
    """
    Sets the announcement status of a group.

    :param jid: The unique identifier of the group
    :type jid: JID
    :param announce: The announcement status to be set. If True, announcements are enabled. If False, they are disabled.
    :type announce: bool
    :raises SetGroupAnnounceError: If there is an error while setting the announcement status
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.SetGroupAnnounce(
        self.uuid, jid_proto, len(jid_proto), announce
    ).decode()
    if err:
        raise SetGroupAnnounceError(err)

set_group_locked

Python
set_group_locked(jid: JID, locked: bool)

Sets the locked status of a group identified by the given JID.

PARAMETER DESCRIPTION
jid

The JID (Jabber ID) of the group to be locked/unlocked.

TYPE: JID

locked

The new locked status of the group. True to lock the group, False to unlock.

TYPE: bool

RAISES DESCRIPTION
SetGroupLockedError

If the operation fails, an error with the reason for the failure is raised.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_group_locked(self, jid: JID, locked: bool):
    """
    Sets the locked status of a group identified by the given JID.

    :param jid: The JID (Jabber ID) of the group to be locked/unlocked.
    :type jid: JID
    :param locked: The new locked status of the group. True to lock the group, False to unlock.
    :type locked: bool
    :raises SetGroupLockedError: If the operation fails, an error with the reason for the failure is raised.
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.SetGroupLocked(
        self.uuid, jid_proto, len(jid_proto), locked
    ).decode()
    if err:
        raise SetGroupLockedError(err)

set_group_topic

Python
set_group_topic(jid: JID, previous_id: str, new_id: str, topic: str)

Set the topic of a group in a chat application.

PARAMETER DESCRIPTION
jid

The unique identifier of the group

TYPE: JID

previous_id

The previous identifier of the topic

TYPE: str

new_id

The new identifier for the topic

TYPE: str

topic

The new topic to be set

TYPE: str

RAISES DESCRIPTION
SetGroupTopicError

If there is an error setting the group topic

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_group_topic(self, jid: JID, previous_id: str, new_id: str, topic: str):
    """
    Set the topic of a group in a chat application.

    :param jid: The unique identifier of the group
    :type jid: JID
    :param previous_id: The previous identifier of the topic
    :type previous_id: str
    :param new_id: The new identifier for the topic
    :type new_id: str
    :param topic: The new topic to be set
    :type topic: str
    :raises SetGroupTopicError: If there is an error setting the group topic
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.SetGroupTopic(
        self.uuid,
        jid_proto,
        len(jid_proto),
        previous_id.encode(),
        new_id.encode(),
        topic.encode(),
    ).decode()
    if err:
        raise SetGroupTopicError(err)

set_privacy_setting

Python
set_privacy_setting(name: PrivacySettingType, value: PrivacySetting)

This method is used to set the privacy settings of a user.

PARAMETER DESCRIPTION
name

The name of the privacy setting to be changed.

TYPE: PrivacySettingType

value

The new value for the privacy setting.

TYPE: PrivacySetting

RAISES DESCRIPTION
SetPrivacySettingError

If there is an error while setting the privacy setting.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_privacy_setting(self, name: PrivacySettingType, value: PrivacySetting):
    """
    This method is used to set the privacy settings of a user.

    :param name: The name of the privacy setting to be changed.
    :type name: PrivacySettingType
    :param value: The new value for the privacy setting.
    :type value: PrivacySetting
    :raises SetPrivacySettingError: If there is an error while setting the privacy setting.
    """
    err = self.__client.SetPrivacySetting(
        self.uuid, name.value.encode(), value.value.encode()
    ).decode()
    if err:
        raise SetPrivacySettingError(err)

set_passive

Python
set_passive(passive: bool)

Sets the passive mode of the client.

PARAMETER DESCRIPTION
passive

If True, sets the client to passive mode. If False, sets the client to active mode.

TYPE: bool

RAISES DESCRIPTION
SetPassiveError

If an error occurs while setting the client to passive mode.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_passive(self, passive: bool):
    """
    Sets the passive mode of the client.

    :param passive: If True, sets the client to passive mode. If False, sets the client to active mode.
    :type passive: bool
    :raises SetPassiveError: If an error occurs while setting the client to passive mode.
    """
    err = self.__client.SetPassive(self.uuid, passive)
    if err:
        raise SetPassiveError(err)

set_status_message

Python
set_status_message(msg: str)

Sets a status message for a client using the client's UUID.

PARAMETER DESCRIPTION
msg

The status message to be set.

TYPE: str

RAISES DESCRIPTION
SetStatusMessageError

If there is an error while setting the status message.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def set_status_message(self, msg: str):
    """
    Sets a status message for a client using the client's UUID.

    :param msg: The status message to be set.
    :type msg: str
    :raises SetStatusMessageError: If there is an error while setting the status message.
    """
    err = self.__client.SetStatusMessage(self.uuid, msg.encode()).decode()
    if err:
        raise SetStatusMessageError(err)

subscribe_presence

Python
subscribe_presence(jid: JID)

This method is used to subscribe to the presence of a certain JID (Jabber ID).

PARAMETER DESCRIPTION
jid

The Jabber ID (JID) that we want to subscribe to.

TYPE: JID

RAISES DESCRIPTION
SubscribePresenceError

If there is an error while subscribing to the presence of the JID.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def subscribe_presence(self, jid: JID):
    """
    This method is used to subscribe to the presence of a certain JID (Jabber ID).

    :param jid: The Jabber ID (JID) that we want to subscribe to.
    :type jid: JID
    :raises SubscribePresenceError: If there is an error while subscribing to the presence of the JID.
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.SubscribePresence(
        self.uuid, jid_proto, len(jid_proto)
    ).decode()
    if err:
        raise SubscribePresenceError(err)

unfollow_newsletter

Python
unfollow_newsletter(jid: JID)

Unfollows a newsletter by providing the JID (Jabber ID) of the newsletter.

PARAMETER DESCRIPTION
jid

The Jabber ID of the newsletter to unfollow.

TYPE: JID

RAISES DESCRIPTION
UnfollowNewsletterError

If there is an error while attempting to unfollow the newsletter.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def unfollow_newsletter(self, jid: JID):
    """
    Unfollows a newsletter by providing the JID (Jabber ID) of the newsletter.

    :param jid: The Jabber ID of the newsletter to unfollow.
    :type jid: JID
    :raises UnfollowNewsletterError: If there is an error while attempting to unfollow the newsletter.
    """
    jid_proto = jid.SerializeToString()
    err = self.__client.UnfollowNewsletter(
        self.uuid, jid_proto, len(jid_proto)
    ).decode()
    if err:
        raise UnfollowNewsletterError(err)
Python
unlink_group(parent: JID, child: JID)

This method is used to unlink a child group from a parent group.

PARAMETER DESCRIPTION
parent

The JID of the parent group from which the child group is to be unlinked.

TYPE: JID

child

The JID of the child group which is to be unlinked from the parent group.

TYPE: JID

RAISES DESCRIPTION
UnlinkGroupError

If there is an error while unlinking the child group from the parent group.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def unlink_group(self, parent: JID, child: JID):
    """
    This method is used to unlink a child group from a parent group.

    :param parent: The JID of the parent group from which the child group is to be unlinked.
    :type parent: JID
    :param child: The JID of the child group which is to be unlinked from the parent group.
    :type child: JID
    :raises UnlinkGroupError: If there is an error while unlinking the child group from the parent group.
    """
    parent_proto = parent.SerializeToString()
    child_proto = child.SerializeToString()
    err = self.__client.UnlinkGroup(
        self.uuid, parent_proto, len(parent_proto), child_proto, len(child_proto)
    ).decode()
    if err:
        raise UnlinkGroupError(err)

update_blocklist

Python
update_blocklist(jid: JID, action: BlocklistAction) -> Blocklist

Function to update the blocklist with a given action on a specific JID.

PARAMETER DESCRIPTION
jid

The Jabber ID (JID) of the user to be blocked or unblocked.

TYPE: JID

action

The action to be performed (block or unblock) on the JID.

TYPE: BlocklistAction

RETURNS DESCRIPTION
Blocklist

The updated blocklist.

RAISES DESCRIPTION
UpdateBlocklistError

If there is an error while updating the blocklist.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def update_blocklist(self, jid: JID, action: BlocklistAction) -> Blocklist:
    """
    Function to update the blocklist with a given action on a specific JID.

    :param jid: The Jabber ID (JID) of the user to be blocked or unblocked.
    :type jid: JID
    :param action: The action to be performed (block or unblock) on the JID.
    :type action: BlocklistAction
    :raises UpdateBlocklistError: If there is an error while updating the blocklist.
    :return: The updated blocklist.
    :rtype: Blocklist
    """
    jid_proto = jid.SerializeToString()
    bytes_ptr = self.__client.UpdateBlocklist(
        self.uuid, jid_proto, len(jid_proto), action.value.encode()
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetBlocklistReturnFunction.FromString(protobytes)
    if model.Error:
        raise UpdateBlocklistError(model.Error)
    return model.Blocklist

update_group_participants

Python
update_group_participants(jid: JID, participants_changes: List[JID], action: ParticipantChange) -> RepeatedCompositeFieldContainer[GroupParticipant]

This method is used to update the list of participants in a group. It takes in the group's JID, a list of participant changes, and an action to perform.

PARAMETER DESCRIPTION
jid

The JID (Jabber ID) of the group to update.

TYPE: JID

participants_changes

A list of JIDs representing the participants to be added or removed.

TYPE: List[JID]

action

The action to perform (add, remove, promote or demote participants).

TYPE: ParticipantChange

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[GroupParticipant]

A list of the updated group participants.

RAISES DESCRIPTION
UpdateGroupParticipantsError

This error is raised if there is a problem updating the group participants.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def update_group_participants(
    self, jid: JID, participants_changes: List[JID], action: ParticipantChange
) -> RepeatedCompositeFieldContainer[GroupParticipant]:
    """
    This method is used to update the list of participants in a group.
    It takes in the group's JID, a list of participant changes, and an action to perform.

    :param jid: The JID (Jabber ID) of the group to update.
    :type jid: JID
    :param participants_changes: A list of JIDs representing the participants to be added or removed.
    :type participants_changes: List[JID]
    :param action: The action to perform (add, remove, promote or demote participants).
    :type action: ParticipantChange
    :raises UpdateGroupParticipantsError: This error is raised if there is a problem updating the group participants.
    :return: A list of the updated group participants.
    :rtype: RepeatedCompositeFieldContainer[GroupParticipant]
    """
    jid_proto = jid.SerializeToString()
    jids_proto = neonize_proto.JIDArray(
        JIDS=participants_changes
    ).SerializeToString()
    bytes_ptr = self.__client.UpdateGroupParticipants(
        self.uuid,
        jid_proto,
        len(jid_proto),
        jids_proto,
        len(jids_proto),
        action.value.encode(),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.UpdateGroupParticipantsReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise UpdateGroupParticipantsError(model.Error)
    return model.participants

upload_newsletter

Python
upload_newsletter(data: bytes, media_type: MediaType) -> UploadResponse

Uploads the newsletter to the server.

PARAMETER DESCRIPTION
data

The newsletter content in bytes.

TYPE: bytes

media_type

The type of media being uploaded.

TYPE: MediaType

RETURNS DESCRIPTION
UploadResponse

The response from the server after the upload.

RAISES DESCRIPTION
UploadError

If there is an error during the upload process.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def upload_newsletter(self, data: bytes, media_type: MediaType) -> UploadResponse:
    """Uploads the newsletter to the server.

    :param data: The newsletter content in bytes.
    :type data: bytes
    :param media_type: The type of media being uploaded.
    :type media_type: MediaType
    :raises UploadError: If there is an error during the upload process.
    :return: The response from the server after the upload.
    :rtype: UploadResponse
    """
    bytes_ptr = self.__client.UploadNewsletter(
        self.uuid, data, len(data), media_type.value
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = UploadReturnFunction.FromString(protobytes)
    if model.Error:
        raise UploadError(model.Error)
    return model.UploadResponse

create_group

Python
create_group(name: str, participants: List[JID] = [], linked_parent: Optional[GroupLinkedParent] = None, group_parent: Optional[GroupParent] = None) -> GroupInfo

Create a new group.

PARAMETER DESCRIPTION
name

The name of the new group.

TYPE: str

participants

Optional. A list of participant JIDs (Jabber Identifiers) to be included in the group. Defaults to an empty list.

TYPE: List[JID] DEFAULT: []

linked_parent

Optional. Information about a linked parent group, if applicable. Defaults to None.

TYPE: Optional[GroupLinkedParent] DEFAULT: None

group_parent

Optional. Information about a parent group, if applicable. Defaults to None.

TYPE: Optional[GroupParent] DEFAULT: None

RETURNS DESCRIPTION
GroupInfo

Information about the newly created group.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def create_group(
    self,
    name: str,
    participants: List[JID] = [],
    linked_parent: Optional[GroupLinkedParent] = None,
    group_parent: Optional[GroupParent] = None,
) -> GroupInfo:
    """Create a new group.

    :param name: The name of the new group.
    :type name: str
    :param participants: Optional. A list of participant JIDs (Jabber Identifiers) to be included in the group. Defaults to an empty list.
    :type participants: List[JID], optional
    :param linked_parent: Optional. Information about a linked parent group, if applicable. Defaults to None.
    :type linked_parent: Optional[GroupLinkedParent], optional
    :param group_parent: Optional. Information about a parent group, if applicable. Defaults to None.
    :type group_parent: Optional[GroupParent], optional
    :return: Information about the newly created group.
    :rtype: GroupInfo
    """
    group_info = ReqCreateGroup(
        name=name, Participants=participants, CreateKey=self.generate_message_id()
    )
    if linked_parent:
        group_info.GroupLinkedParent.MergeFrom(linked_parent)
    if group_parent:
        group_info.GroupParent.MergeFrom(group_parent)
    group_info_buf = group_info.SerializeToString()
    bytes_ptr = self.__client.CreateGroup(
        self.uuid, group_info_buf, len(group_info_buf)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = GetGroupInfoReturnFunction.FromString(protobytes)
    if model.Error:
        raise CreateGroupError(model.Error)
    return model.GroupInfo

get_group_request_participants

Python
get_group_request_participants(jid: JID) -> RepeatedCompositeFieldContainer[GroupParticipantRequest]

Get the participants of a group request.

PARAMETER DESCRIPTION
jid

The JID of the group request.

TYPE: JID

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[JID]

A list of JIDs representing the participants of the group request.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_group_request_participants(
    self, jid: JID
) -> RepeatedCompositeFieldContainer[GroupParticipantRequest]:
    """Get the participants of a group request.

    :param jid: The JID of the group request.
    :type jid: JID
    :return: A list of JIDs representing the participants of the group request.
    :rtype: RepeatedCompositeFieldContainer[JID]
    """
    jidbyte = jid.SerializeToString()
    bytes_ptr = self.__client.GetGroupRequestParticipants(
        self.uuid, jidbyte, len(jidbyte)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetGroupRequestParticipantsReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise GetGroupRequestParticipantsError(model.Error)
    return model.Participants

get_joined_groups

Python
get_joined_groups() -> RepeatedCompositeFieldContainer[GroupInfo]

Get the joined groups for the current user.

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[GroupInfo]

A list of :class:GroupInfo objects representing the joined groups.

RAISES DESCRIPTION
GetJoinedGroupsError

If there was an error retrieving the joined groups.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_joined_groups(self) -> RepeatedCompositeFieldContainer[GroupInfo]:
    """Get the joined groups for the current user.

    :return: A list of :class:`GroupInfo` objects representing the joined groups.
    :rtype: RepeatedCompositeFieldContainer[GroupInfo]

    :raises GetJoinedGroupsError: If there was an error retrieving the joined groups.
    """
    bytes_ptr = self.__client.GetJoinedGroups(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetJoinedGroupsReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetJoinedGroupsError(model.Error)
    return model.Group

create_newsletter

Python
create_newsletter(name: str, description: str, picture: Union[str, bytes]) -> NewsletterMetadata

Create a newsletter with the given name, description, and picture.

PARAMETER DESCRIPTION
name

The name of the newsletter.

TYPE: str

description

The description of the newsletter.

TYPE: str

picture

The picture of the newsletter. It can be either a URL or bytes.

TYPE: Union[str, bytes]

RETURNS DESCRIPTION
NewsletterMetadata

The metadata of the created newsletter.

RAISES DESCRIPTION
CreateNewsletterError

If there is an error creating the newsletter.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def create_newsletter(
    self, name: str, description: str, picture: typing.Union[str, bytes]
) -> NewsletterMetadata:
    """Create a newsletter with the given name, description, and picture.

    :param name: The name of the newsletter.
    :type name: str
    :param description: The description of the newsletter.
    :type description: str
    :param picture: The picture of the newsletter. It can be either a URL or bytes.
    :type picture: Union[str, bytes]
    :return: The metadata of the created newsletter.
    :rtype: NewsletterMetadata
    :raises CreateNewsletterError: If there is an error creating the newsletter.
    """
    protobuf = neonize_proto.CreateNewsletterParams(
        Name=name,
        Description=description,
        Picture=get_bytes_from_name_or_url(picture),
    ).SerializeToString()
    bytes_ptr = self.__client.CreateNewsletter(self.uuid, protobuf, len(protobuf))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.CreateNewsLetterReturnFunction.FromString(protobytes)
    if model.Error:
        raise CreateNewsletterError(model.Error)
    return model.NewsletterMetadata

follow_newsletter

Python
follow_newsletter(jid: JID)

Follows a newsletter with the given JID.

PARAMETER DESCRIPTION
jid

The JID of the newsletter to follow.

TYPE: JID

RETURNS DESCRIPTION
None

None

RAISES DESCRIPTION
FollowNewsletterError

If there is an error following the newsletter.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def follow_newsletter(self, jid: JID):
    """Follows a newsletter with the given JID.

    :param jid: The JID of the newsletter to follow.
    :type jid: JID
    :return: None
    :rtype: None
    :raises FollowNewsletterError: If there is an error following the newsletter.
    """

    jidbyte = jid.SerializeToString()
    err = self.__client.FollowNewsletter(self.uuid, jidbyte, len(jidbyte)).decode()
    if err:
        raise FollowNewsletterError(err)

get_newsletter_info_with_invite

Python
get_newsletter_info_with_invite(key: str) -> NewsletterMetadata

Retrieves the newsletter information with an invite using the provided key.

PARAMETER DESCRIPTION
key

The key used to identify the newsletter.

TYPE: str

RETURNS DESCRIPTION
NewsletterMetadata

The newsletter metadata.

RAISES DESCRIPTION
GetNewsletterInfoWithInviteError

If there is an error retrieving the newsletter information.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_newsletter_info_with_invite(self, key: str) -> NewsletterMetadata:
    """Retrieves the newsletter information with an invite using the provided key.

    :param key: The key used to identify the newsletter.
    :type key: str
    :return: The newsletter metadata.
    :rtype: NewsletterMetadata
    :raises GetNewsletterInfoWithInviteError: If there is an error retrieving the newsletter information.
    """
    bytes_ptr = self.__client.GetNewsletterInfoWithInvite(self.uuid, key.encode())
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.CreateNewsLetterReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetNewsletterInfoWithInviteError(model.Error)
    return model.NewsletterMetadata

get_newsletter_message_update

Python
get_newsletter_message_update(jid: JID, count: int, since: int, after: int) -> RepeatedCompositeFieldContainer[NewsletterMessage]

Retrieves a list of newsletter messages that have been updated since a given timestamp.

PARAMETER DESCRIPTION
jid

The JID (Jabber ID) of the user.

TYPE: JID

count

The maximum number of messages to retrieve.

TYPE: int

since

The timestamp (in milliseconds) to retrieve messages from.

TYPE: int

after

The timestamp (in milliseconds) to retrieve messages after.

TYPE: int

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[NewsletterMessage]

A list of updated newsletter messages.

RAISES DESCRIPTION
GetNewsletterMessageUpdateError

If there was an error retrieving the newsletter messages.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_newsletter_message_update(
    self, jid: JID, count: int, since: int, after: int
) -> RepeatedCompositeFieldContainer[NewsletterMessage]:
    """Retrieves a list of newsletter messages that have been updated since a given timestamp.

    :param jid: The JID (Jabber ID) of the user.
    :type jid: JID
    :param count: The maximum number of messages to retrieve.
    :type count: int
    :param since: The timestamp (in milliseconds) to retrieve messages from.
    :type since: int
    :param after: The timestamp (in milliseconds) to retrieve messages after.
    :type after: int

    :return: A list of updated newsletter messages.
    :rtype: RepeatedCompositeFieldContainer[NewsletterMessage]

    :raises GetNewsletterMessageUpdateError: If there was an error retrieving the newsletter messages.
    """
    jidbyte = jid.SerializeToString()
    bytes_ptr = self.__client.GetNewsletterMessageUpdate(
        self.uuid, jidbyte, len(jidbyte), count, since, after
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetNewsletterMessageUpdateReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise GetNewsletterMessageUpdateError(model.Error)
    return model.NewsletterMessage

get_newsletter_messages

Python
get_newsletter_messages(jid: JID, count: int, before: MessageServerID) -> RepeatedCompositeFieldContainer[NewsletterMessage]

Retrieves a list of newsletter messages for a given JID.

PARAMETER DESCRIPTION
jid

The JID (Jabber Identifier) of the user.

TYPE: JID

count

The maximum number of messages to retrieve.

TYPE: int

before

The ID of the message before which to retrieve messages.

TYPE: MessageServerID

RETURNS DESCRIPTION
RepeatedCompositeFieldContaine[NewsletterMessage]

A list of newsletter messages.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_newsletter_messages(
    self, jid: JID, count: int, before: MessageServerID
) -> RepeatedCompositeFieldContainer[NewsletterMessage]:
    """Retrieves a list of newsletter messages for a given JID.

    :param jid: The JID (Jabber Identifier) of the user.
    :type jid: JID
    :param count: The maximum number of messages to retrieve.
    :type count: int
    :param before: The ID of the message before which to retrieve messages.
    :type before: MessageServerID
    :return: A list of newsletter messages.
    :rtype: RepeatedCompositeFieldContaine[NewsletterMessage]
    """
    jidbyte = jid.SerializeToString()
    bytes_ptr = self.__client.GetNewsletterMessages(
        self.uuid, jidbyte, len(jidbyte), count, before
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetNewsletterMessageUpdateReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise GetNewsletterMessagesError(model.Error)
    return model.NewsletterMessage

get_privacy_settings

Python
get_privacy_settings() -> PrivacySettings

This function retrieves the my privacy settings.

RETURNS DESCRIPTION
PrivacySettings

privacy settings

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_privacy_settings(self) -> PrivacySettings:
    """
    This function retrieves the my privacy settings.

    :return: privacy settings
    :rtype: PrivacySettings
    """
    bytes_ptr = self.__client.GetPrivacySettings(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    result = neonize_proto.PrivacySettings.FromString(protobytes)
    return result

get_profile_picture

Python
get_profile_picture(jid: JID, extra: GetProfilePictureParams = neonize_proto.GetProfilePictureParams()) -> ProfilePictureInfo

This function is used to get the profile picture of a user.

PARAMETER DESCRIPTION
jid

The unique identifier of the user whose profile picture we want to retrieve.

TYPE: JID

extra

Additional parameters, defaults to neonize_proto.GetProfilePictureParams()

TYPE: GetProfilePictureParams DEFAULT: GetProfilePictureParams()

RETURNS DESCRIPTION
ProfilePictureInfo

The information about the profile picture.

RAISES DESCRIPTION
GetProfilePictureError

If there is an error while trying to get the profile picture.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_profile_picture(
    self,
    jid: JID,
    extra: neonize_proto.GetProfilePictureParams = neonize_proto.GetProfilePictureParams(),
) -> ProfilePictureInfo:
    """
    This function is used to get the profile picture of a user.

    :param jid: The unique identifier of the user whose profile picture we want to retrieve.
    :type jid: JID
    :param extra: Additional parameters, defaults to neonize_proto.GetProfilePictureParams()
    :type extra: neonize_proto.GetProfilePictureParams, optional
    :raises GetProfilePictureError: If there is an error while trying to get the profile picture.
    :return: The information about the profile picture.
    :rtype: ProfilePictureInfo
    """
    jid_bytes = jid.SerializeToString()
    extra_bytes = extra.SerializeToString()
    bytes_ptr = self.__client.GetProfilePicture(
        self.uuid,
        jid_bytes,
        len(jid_bytes),
        extra_bytes,
        len(extra_bytes),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetProfilePictureReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetProfilePictureError(model)
    return model.Picture

get_status_privacy

Python
get_status_privacy() -> RepeatedCompositeFieldContainer[StatusPrivacy]

Returns the status privacy settings of the user.

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[StatusPrivacy]

The status privacy settings of the user.

RAISES DESCRIPTION
GetStatusPrivacyError

If there is an error in getting the status privacy.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_status_privacy(
    self,
) -> RepeatedCompositeFieldContainer[StatusPrivacy]:
    """Returns the status privacy settings of the user.

    :raises GetStatusPrivacyError: If there is an error in getting the status privacy.
    :return: The status privacy settings of the user.
    :rtype: RepeatedCompositeFieldContainer[StatusPrivacy]
    """
    bytes_ptr = self.__client.GetStatusPrivacy(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetStatusPrivacyReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetStatusPrivacyError(model.Error)
    return model.StatusPrivacy

get_sub_groups

Python
get_sub_groups(community: JID) -> RepeatedCompositeFieldContainer[GroupLinkTarget]

Get the subgroups of a given community.

PARAMETER DESCRIPTION
community

The community for which to get the subgroups.

TYPE: JID

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[GroupLinkTarget]

The subgroups of the given community.

RAISES DESCRIPTION
GetSubGroupsError

If there is an error while getting the subgroups.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_sub_groups(
    self, community: JID
) -> RepeatedCompositeFieldContainer[GroupLinkTarget]:
    """
    Get the subgroups of a given community.

    :param community: The community for which to get the subgroups.
    :type community: JID
    :raises GetSubGroupsError: If there is an error while getting the subgroups.
    :return: The subgroups of the given community.
    :rtype: RepeatedCompositeFieldContainer[GroupLinkTarget]
    """
    jid = community.SerializeToString()
    bytes_ptr = self.__client.GetSubGroups(self.uuid, jid, len(jid))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetSubGroupsReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetSubGroupsError(model.Error)
    return model.GroupLinkTarget

get_subscribed_newletters

Python
get_subscribed_newletters() -> RepeatedCompositeFieldContainer[NewsletterMetadata]

This function retrieves the newsletters the user has subscribed to.

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[NewsletterMetadata]

A container with the metadata of each subscribed newsletter

RAISES DESCRIPTION
GetSubscribedNewslettersError

If there is an error while fetching the subscribed newsletters

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_subscribed_newletters(
    self,
) -> RepeatedCompositeFieldContainer[NewsletterMetadata]:
    """
    This function retrieves the newsletters the user has subscribed to.

    :raises GetSubscribedNewslettersError: If there is an error while fetching the subscribed newsletters
    :return: A container with the metadata of each subscribed newsletter
    :rtype: RepeatedCompositeFieldContainer[NewsletterMetadata]
    """
    bytes_ptr = self.__client.GetSubscribedNewsletters(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetSubscribedNewslettersReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise GetSubscribedNewslettersError(model.Error)
    return model.Newsletter

get_user_devices

Python
get_user_devices(*jids: JID) -> RepeatedCompositeFieldContainer[JID]

Retrieve devices associated with specified user JIDs.

PARAMETER DESCRIPTION
jids

Variable number of JIDs (Jabber Identifiers) of users.

TYPE: JID DEFAULT: ()

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[JID]

Devices associated with the specified user JIDs.

RAISES DESCRIPTION
GetUserDevicesError

If there is an error retrieving user devices.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_user_devices(self, *jids: JID) -> RepeatedCompositeFieldContainer[JID]:
    """
    Retrieve devices associated with specified user JIDs.

    :param jids: Variable number of JIDs (Jabber Identifiers) of users.
    :type jids: JID
    :raises GetUserDevicesError: If there is an error retrieving user devices.
    :return: Devices associated with the specified user JIDs.
    :rtype: RepeatedCompositeFieldContainer[JID]
    """
    jids_ = neonize_proto.JIDArray(JIDS=jids).SerializeToString()
    bytes_ptr = self.__client.GetUserDevices(self.uuid, jids_, len(jids_))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetUserDevicesreturnFunction.FromString(protobytes)
    if model.Error:
        raise GetUserDevicesError(model.Error)
    return model.JID

get_blocklist

Python
get_blocklist() -> Blocklist

Retrieves the blocklist from the client.

RETURNS DESCRIPTION
Blocklist

Blocklist: The retrieved blocklist.

RAISES DESCRIPTION
GetBlocklistError

If there was an error retrieving the blocklist.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_blocklist(self) -> Blocklist:
    """Retrieves the blocklist from the client.

    :return: Blocklist: The retrieved blocklist.
    :raises GetBlocklistError: If there was an error retrieving the blocklist.
    """
    bytes_ptr = self.__client.GetBlocklist(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetBlocklistReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetBlocklistError(model.Error)
    return model.Blocklist

get_me

Python
get_me() -> Device

This method is used to get the device information associated with a given UUID.

RETURNS DESCRIPTION
Device

It returns a Device object created from the byte string response from the client's GetMe method.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_me(self) -> Device:
    """
    This method is used to get the device information associated with a given UUID.

    :return: It returns a Device object created from the byte string response from the client's GetMe method.
    :rtype: Device
    """
    bytes_ptr = self.__client.GetMe(self.uuid)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    result = Device.FromString(protobytes)
    return result
Python
get_contact_qr_link(revoke: bool = False) -> str

This function returns a QR link for a specific contact. If the 'revoke' parameter is set to True, it revokes the existing QR link and generates a new one.

PARAMETER DESCRIPTION
revoke

If set to True, revokes the existing QR link and generates a new one. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

The QR link for the contact.

RAISES DESCRIPTION
GetContactQrLinkError

If there is an error in getting the QR link.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_contact_qr_link(self, revoke: bool = False) -> str:
    """
    This function returns a QR link for a specific contact. If the 'revoke' parameter is set to True,
    it revokes the existing QR link and generates a new one.

    :param revoke: If set to True, revokes the existing QR link and generates a new one. Defaults to False.
    :type revoke: bool, optional
    :raises GetContactQrLinkError: If there is an error in getting the QR link.
    :return: The QR link for the contact.
    :rtype: str
    """
    bytes_ptr = self.__client.GetContactQRLink(self.uuid, revoke)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetContactQRLinkReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetContactQrLinkError(model.Error)
    return model.Link

get_linked_group_participants

Python
get_linked_group_participants(community: JID) -> RepeatedCompositeFieldContainer[GroupParticipantRequest]

Fetches the participants of a linked group in a community.

PARAMETER DESCRIPTION
community

The community in which the linked group belongs.

TYPE: JID

RETURNS DESCRIPTION
RepeatedCompositeFieldContainer[JID]

A list of participants in the linked group.

RAISES DESCRIPTION
GetLinkedGroupParticipantsError

If there is an error while fetching the participants.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_linked_group_participants(
    self, community: JID
) -> RepeatedCompositeFieldContainer[GroupParticipantRequest]:
    """Fetches the participants of a linked group in a community.

    :param community: The community in which the linked group belongs.
    :type community: JID
    :raises GetLinkedGroupParticipantsError: If there is an error while fetching the participants.
    :return: A list of participants in the linked group.
    :rtype: RepeatedCompositeFieldContainer[JID]
    """
    jidbyte = community.SerializeToString()
    bytes_ptr = self.__client.GetLinkedGroupsParticipants(
        self.uuid, jidbyte, len(jidbyte)
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetGroupRequestParticipantsReturnFunction.FromString(
        protobytes
    )
    if model.Error:
        raise GetLinkedGroupParticipantsError(model.Error)
    return model.Participants

get_newsletter_info

Python
get_newsletter_info(jid: JID) -> neonize_proto.NewsletterMetadata

Fetches the metadata of a specific newsletter using its JID.

PARAMETER DESCRIPTION
jid

The unique identifier of the newsletter

TYPE: JID

RETURNS DESCRIPTION
neonize_proto.NewsletterMetadata

The metadata of the requested newsletter

RAISES DESCRIPTION
GetNewsletterInfoError

If there is an error while fetching the newsletter information

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_newsletter_info(self, jid: JID) -> neonize_proto.NewsletterMetadata:
    """
    Fetches the metadata of a specific newsletter using its JID.

    :param jid: The unique identifier of the newsletter
    :type jid: JID
    :raises GetNewsletterInfoError: If there is an error while fetching the newsletter information
    :return: The metadata of the requested newsletter
    :rtype: neonize_proto.NewsletterMetadata
    """
    jidbyte = jid.SerializeToString()
    bytes_ptr = self.__client.GetNewsletterInfo(self.uuid, jidbyte, len(jidbyte))
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.CreateNewsLetterReturnFunction.FromString(protobytes)
    if model.Error:
        raise GetNewsletterInfoError(model.Error)
    return model.NewsletterMetadata

PairPhone

Python
PairPhone(phone: str, show_push_notification: bool, client_name: ClientName = ClientName.LINUX, client_type: Optional[ClientType] = None)

Pair a phone with the client. This function will try to connect to the WhatsApp servers and pair the phone. If successful, it will show a push notification on the paired phone.

PARAMETER DESCRIPTION
phone

The phone number to be paired.

TYPE: str

show_push_notification

If true, a push notification will be shown on the paired phone.

TYPE: bool

client_name

The name of the client, defaults to LINUX.

TYPE: ClientName DEFAULT: LINUX

client_type

The type of the client, defaults to None. If None, it will be set to FIREFOX or determined by the device properties.

TYPE: Optional[ClientType] DEFAULT: None

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def PairPhone(
    self,
    phone: str,
    show_push_notification: bool,
    client_name: ClientName = ClientName.LINUX,
    client_type: Optional[ClientType] = None,
):
    """
    Pair a phone with the client. This function will try to connect to the WhatsApp servers and pair the phone.
    If successful, it will show a push notification on the paired phone.

    :param phone: The phone number to be paired.
    :type phone: str
    :param show_push_notification: If true, a push notification will be shown on the paired phone.
    :type show_push_notification: bool
    :param client_name: The name of the client, defaults to LINUX.
    :type client_name: ClientName, optional
    :param client_type: The type of the client, defaults to None. If None, it will be set to FIREFOX or determined by the device properties.
    :type client_type: Optional[ClientType], optional
    """

    if client_type is None:
        if self.device_props is None:
            client_type = ClientType.FIREFOX
        else:
            try:
                client_type = ClientType(self.device_props.platformType)
            except ValueError:
                client_type = ClientType.FIREFOX

    pl = neonize_proto.PairPhoneParams(
        phone=phone,
        clientDisplayName="%s (%s)" % (client_type.name, client_name.name),
        clientType=client_type.value,
        showPushNotification=show_push_notification,
    )
    payload = pl.SerializeToString()
    d = bytearray(list(self.event.list_func))

    _log_.debug("trying connect to whatsapp servers")

    deviceprops = (
        DeviceProps(os="Neonize", platformType=DeviceProps.SAFARI)
        if self.device_props is None
        else self.device_props
    ).SerializeToString()

    jidbuf_size = 0
    jidbuf = b""
    if self.jid:
        jidbuf = self.jid.SerializeToString()
        jidbuf_size = len(jidbuf)

    self.__client.Neonize(
        self.name.encode(),
        self.uuid,
        jidbuf,
        jidbuf_size,
        LogLevel.from_logging(log.level).level,
        func_string(self.__onQr),
        func_string(self.__onLoginStatus),
        func_callback_bytes(self.event.execute),
        func_callback_bytes2(log_whatsmeow),
        (ctypes.c_char * self.event.list_func.__len__()).from_buffer(d),
        len(d),
        deviceprops,
        len(deviceprops),
        payload,
        len(payload),
    )

stop

Python
stop()

Stops the client by disconnecting it from the WhatsApp servers.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def stop(self):
    """
    Stops the client by disconnecting it from the WhatsApp servers.
    """
    _log_.debug("Stopping client and disconnecting from WhatsApp servers.")
    self.__client.stop()

get_message_for_retry

Python
get_message_for_retry(requester: JID, to: JID, message_id: str) -> typing.Union[None, Message]

This function retrieves a specific message for retrying transmission. It communicates with a client to get the message using provided requester, recipient, and message ID.

PARAMETER DESCRIPTION
requester

The JID of the entity requesting the message.

TYPE: JID

to

The JID of the intended recipient of the message.

TYPE: JID

message_id

The unique identifier of the message to be retrieved.

TYPE: str

RETURNS DESCRIPTION
Union[None, Message]

The message to be retried if found, None otherwise.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def get_message_for_retry(
    self, requester: JID, to: JID, message_id: str
) -> typing.Union[None, Message]:
    """
    This function retrieves a specific message for retrying transmission.
    It communicates with a client to get the message using provided requester, recipient, and message ID.

    :param requester: The JID of the entity requesting the message.
    :type requester: JID
    :param to: The JID of the intended recipient of the message.
    :type to: JID
    :param message_id: The unique identifier of the message to be retrieved.
    :type message_id: str
    :return: The message to be retried if found, None otherwise.
    :rtype: Union[None, Message]
    """
    requester_buf = requester.SerializeToString()
    to_buf = to.SerializeToString()
    bytes_ptr = self.__client.GetMessageForRetry(
        self.uuid,
        requester_buf,
        len(requester_buf),
        to_buf,
        len(to_buf),
        message_id.encode(),
    )
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = neonize_proto.GetMessageForRetryReturnFunction.FromString(protobytes)
    if model.Error:
        raise Exception(model.Error)
    if not model.isEmpty:
        return model.Message

decrypt_poll_vote

Python
decrypt_poll_vote(message: Message) -> PollVoteMessage

Decrypt PollMessage

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def decrypt_poll_vote(self, message: neonize_proto.Message) -> PollVoteMessage:
    """Decrypt PollMessage"""
    msg_buff = message.SerializeToString()
    bytes_ptr = self.__client.DecryptPollVote(self.uuid, msg_buff)
    protobytes = bytes_ptr.contents.get_bytes()
    free_bytes(bytes_ptr)
    model = ReturnFunctionWithError.FromString(protobytes)
    if model.Error:
        raise DecryptPollVoteError(model.Error)
    return model.PollVoteMessage

connect

Python
connect()

Establishes a connection to the WhatsApp servers.

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def connect(self):
    """Establishes a connection to the WhatsApp servers."""
    # Convert the list of functions to a bytearray
    d = bytearray(list(self.event.list_func))
    _log_.debug("đź”’ Attempting to connect to the WhatsApp servers.")
    # Set device properties
    deviceprops = (
        DeviceProps(os="Neonize", platformType=DeviceProps.SAFARI)
        if self.device_props is None
        else self.device_props
    ).SerializeToString()

    jidbuf_size = 0
    jidbuf = b""
    if self.jid:
        jidbuf = self.jid.SerializeToString()
        jidbuf_size = len(jidbuf)

    # Initiate connection to the server
    self.__client.Neonize(
        self.name.encode(),
        self.uuid,
        jidbuf,
        jidbuf_size,
        LogLevel.from_logging(log.level).level,
        func_string(self.__onQr),
        func_string(self.__onLoginStatus),
        func_callback_bytes(self.event.execute),
        func_callback_bytes2(log_whatsmeow),
        (ctypes.c_char * len(self.event.list_func)).from_buffer(d),
        len(d),
        deviceprops,
        len(deviceprops),
        b"",
        0,
    )

disconnect

Python
disconnect() -> None

Disconnect the client

Source code in .venv/lib/python3.12/site-packages/neonize/client.py
Python
def disconnect(self) -> None:
    """
    Disconnect the client
    """
    self.__client.Disconnect(self.uuid)

Overview

NewClient is the main synchronous client for interacting with WhatsApp through Neonize. It provides a complete interface for sending messages, handling media, managing groups, and responding to events.

Constructor

Python
1
2
3
4
5
6
7
from neonize.client import NewClient

client = NewClient(
    name: str,
    database: str = None,
    props: DeviceProps = None
)

Parameters

Parameter Type Default Description
name str Required Unique identifier for this client session
database str None Database connection string (SQLite or PostgreSQL)
props DeviceProps None Custom device properties

Examples

Python
# Basic client with default SQLite database
client = NewClient("my_bot")

# Custom database path
client = NewClient("my_bot", database="./sessions/bot.db")

# PostgreSQL database
client = NewClient(
    "production_bot",
    database="postgresql://user:pass@localhost:5432/whatsapp"
)

# Custom device properties
from neonize.proto.waCompanionReg.WAWebProtobufsCompanionReg_pb2 import DeviceProps

props = DeviceProps(os="Custom Bot v1.0")
client = NewClient("custom_bot", props=props)

Connection Methods

connect()

Establish connection to WhatsApp servers.

Python
client.connect()

Raises: - ConnectionError: If connection fails

Example:

Python
1
2
3
4
5
try:
    client.connect()
    print("Connected successfully!")
except ConnectionError as e:
    print(f"Connection failed: {e}")

disconnect()

Gracefully disconnect from WhatsApp.

Python
client.disconnect()

Example:

Python
client.disconnect()
print("Disconnected")

logout()

Logout from WhatsApp and clear session.

Python
client.logout()

Example:

Python
client.logout()
print("Logged out and session cleared")

Message Methods

send_message()

Send a text message or custom message object.

Python
1
2
3
4
5
6
7
response = client.send_message(
    to: str,
    message: Union[str, Message],
    link_preview: bool = False,
    ghost_mentions: str = "",
    add_msg_secret: bool = False
)

Parameters:

Parameter Type Default Description
to str Required Recipient JID
message str\|Message Required Message text or Message object
link_preview bool False Enable link preview
ghost_mentions str "" Mention users without notification
add_msg_secret bool False Add message secret

Returns: SendResponse - Contains message ID and timestamp

Example:

Python
from neonize.utils import build_jid

recipient = build_jid("1234567890")

# Simple text
response = client.send_message(recipient, "Hello!")
print(f"Sent: {response.ID}")

# With link preview
client.send_message(
    recipient,
    "Check this: https://github.com/krypton-byte/neonize",
    link_preview=True
)

# With ghost mentions
client.send_message(
    recipient,
    "Secret mention",
    ghost_mentions="@1234567890"
)

reply_message()

Reply to a message.

Python
1
2
3
4
5
6
response = client.reply_message(
    text: str,
    quoted: MessageEv,
    link_preview: bool = False,
    reply_privately: bool = False
)

Parameters:

Parameter Type Default Description
text str Required Reply text
quoted MessageEv Required Message to reply to
link_preview bool False Enable link preview
reply_privately bool False Reply privately in groups

Example:

Python
from neonize.events import MessageEv

@client.event(MessageEv)
def on_message(client: NewClient, event: MessageEv):
    # Reply to message
    client.reply_message("Thanks!", event)

    # Private reply in group
    client.reply_message(
        "This is private",
        event,
        reply_privately=True
    )

edit_message()

Edit a sent message.

Python
1
2
3
4
5
client.edit_message(
    chat: str,
    message_id: str,
    new_message: Message
)

Example:

Python
1
2
3
4
from neonize.proto.waE2E.WAWebProtobufsE2E_pb2 import Message

new_msg = Message(conversation="Updated text")
client.edit_message(chat_jid, "MSG_ID", new_msg)

revoke_message()

Delete a message for everyone.

Python
1
2
3
4
5
client.revoke_message(
    chat: str,
    sender: str,
    message_id: str
)

Example:

Python
client.revoke_message(chat_jid, sender_jid, "MSG_ID")

Media Methods

send_image()

Send an image message.

Python
1
2
3
4
5
6
response = client.send_image(
    to: str,
    image: Union[str, bytes],
    caption: str = "",
    viewonce: bool = False
)

Parameters:

Parameter Type Description
to str Recipient JID
image str\|bytes Image path, URL, or bytes
caption str Image caption
viewonce bool View once mode

Example:

Python
# From file
client.send_image(recipient, "photo.jpg", caption="Check this!")

# From URL
client.send_image(
    recipient,
    "https://example.com/image.jpg",
    caption="Downloaded image"
)

# From bytes
with open("image.jpg", "rb") as f:
    data = f.read()
client.send_image(recipient, data)

# View once
client.send_image(recipient, "secret.jpg", viewonce=True)

send_video()

Send a video message.

Python
1
2
3
4
5
6
7
8
response = client.send_video(
    to: str,
    video: Union[str, bytes],
    caption: str = "",
    viewonce: bool = False,
    gifplayback: bool = False,
    is_gif: bool = False
)

Example:

Python
1
2
3
4
5
6
7
8
# Regular video
client.send_video(recipient, "video.mp4", caption="My video")

# As GIF
client.send_video(recipient, "animation.mp4", gifplayback=True)

# From GIF file
client.send_video(recipient, "animation.gif", is_gif=True)

send_audio()

Send an audio message.

Python
1
2
3
4
5
response = client.send_audio(
    to: str,
    audio: Union[str, bytes],
    ptt: bool = False
)

Parameters:

Parameter Type Description
to str Recipient JID
audio str\|bytes Audio path or bytes
ptt bool Push-to-talk (voice note)

Example:

Python
1
2
3
4
5
# Audio file
client.send_audio(recipient, "song.mp3")

# Voice note
client.send_audio(recipient, "voice.ogg", ptt=True)

send_document()

Send a document.

Python
1
2
3
4
5
6
7
8
response = client.send_document(
    to: str,
    document: Union[str, bytes],
    filename: str = "",
    mimetype: str = "",
    caption: str = "",
    title: str = ""
)

Example:

Python
1
2
3
4
5
6
7
client.send_document(
    recipient,
    "report.pdf",
    filename="Monthly_Report.pdf",
    caption="Here's the report",
    title="Monthly Report"
)

send_sticker()

Send a sticker.

Python
1
2
3
4
5
6
7
response = client.send_sticker(
    to: str,
    sticker: Union[str, bytes],
    name: str = "@MyBot",
    packname: str = "2024",
    crop: bool = False
)

Example:

Python
# Simple sticker
client.send_sticker(recipient, "sticker.webp")

# With metadata
client.send_sticker(
    recipient,
    "image.png",
    name="@MyBot",
    packname="2024",
    crop=True
)

download_any()

Download media from a message.

Python
1
2
3
4
data = client.download_any(
    message: Message,
    path: str = None
)

Returns: bytes if path is None, else saves to file

Example:

Python
from neonize.events import MessageEv

@client.event(MessageEv)
def on_message(client: NewClient, event: MessageEv):
    msg = event.Message

    # Download to memory
    if msg.imageMessage:
        image_data = client.download_any(msg)
        print(f"Downloaded {len(image_data)} bytes")

    # Download to file
    if msg.documentMessage:
        filename = msg.documentMessage.fileName
        client.download_any(msg, path=f"downloads/{filename}")

Group Methods

get_group_info()

Get group information.

Python
info = client.get_group_info(group_jid: str)

Returns: Group metadata

create_group()

Create a new group.

Python
1
2
3
4
group = client.create_group(
    name: str,
    participants: List[str]
)

update_group_name()

Update group name.

Python
1
2
3
4
client.update_group_name(
    group_jid: str,
    name: str
)

Utility Methods

get_me()

Get own user information.

Python
me = client.get_me()
print(f"My JID: {me.JID.User}")

is_on_whatsapp()

Check if numbers are on WhatsApp.

Python
1
2
3
4
5
results = client.is_on_whatsapp("1234567890", "0987654321")

for result in results:
    if result.is_in:
        print(f"{result.jid} is on WhatsApp")

mark_read()

Mark messages as read.

Python
1
2
3
4
5
6
7
8
from neonize.utils.enum import ReceiptType

client.mark_read(
    message_ids: List[str],
    chat: str,
    sender: str,
    receipt: ReceiptType = ReceiptType.READ
)

Event Decorator

@client.event(EventType)

Register event handlers for a specific event type.

Python
1
2
3
4
5
6
7
8
9
from neonize.events import MessageEv, ReceiptEv

@client.event(MessageEv)
def on_message(client: NewClient, event: MessageEv):
    print("Message received!")

@client.event(ReceiptEv)
def on_receipt(client: NewClient, event: ReceiptEv):
    print("Receipt received!")

Properties

is_connected

Check if client is connected.

Python
if client.is_connected:
    print("Connected!")

is_logged_in

Check if client is logged in.

Python
if client.is_logged_in:
    print("Logged in!")

See Also