adjusts in package

This commit is contained in:
Davidson Gomes
2024-10-30 12:00:25 -03:00
parent d49498dbc7
commit 6d49f66bf6
98 changed files with 2097 additions and 19 deletions

View File

View File

@@ -0,0 +1,13 @@
from typing import Union, BinaryIO
from ..models.call import *
class CallService:
def __init__(self, client):
self.client = client
def fake_call(self, instance_id: str, data: FakeCall, instance_token: str):
return self.client.post(
f'call/offer/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)

View File

@@ -0,0 +1,69 @@
from typing import Union, BinaryIO
from ..models.chat import *
class ChatService:
def __init__(self, client):
self.client = client
def check_is_whatsapp_numbers(self, instance_id: str, data: CheckIsWhatsappNumber, instance_token: str):
return self.client.post(
f'chat/checkIsWhatsappNumber/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def mark_message_as_read(self, instance_id: str, messages: List[ReadMessage], instance_token: str):
return self.client.post(
f'chat/markMessageAsRead/{instance_id}',
data={"readMessages": [m.__dict__ for m in messages]},
instance_token=instance_token
)
def archive_chat(self, instance_id: str, data: ArchiveChat, instance_token: str):
return self.client.post(
f'chat/archiveChat/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def mark_chat_unread(self, instance_id: str, data: UnreadChat, instance_token: str):
return self.client.post(
f'chat/markChatUnread/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def delete_message_for_everyone(self, instance_id: str, data: MessageKey, instance_token: str):
return self.client.delete(
f'chat/deleteMessageForEveryone/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def fetch_profile_picture_url(self, instance_id: str, data: ProfilePicture, instance_token: str):
return self.client.post(
f'chat/fetchProfilePictureUrl/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def get_base64_from_media_message(self, instance_id: str, data: MediaMessage, instance_token: str):
return self.client.post(
f'chat/getBase64FromMediaMessage/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_message(self, instance_id: str, data: UpdateMessage, instance_token: str):
return self.client.post(
f'chat/updateMessage/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def send_presence(self, instance_id: str, data: Presence, instance_token: str):
return self.client.post(
f'chat/sendPresence/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)

View File

@@ -0,0 +1,117 @@
from typing import Optional
from ..models.group import *
class GroupService:
def __init__(self, client):
self.client = client
def create_group(self, instance_id: str, data: CreateGroup, instance_token: str):
return self.client.post(
f'group/create/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_group_picture(self, instance_id: str, group_jid: str, data: GroupPicture, instance_token: str):
return self.client.post(
f'group/updateGroupPicture/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def update_group_subject(self, instance_id: str, group_jid: str, data: GroupSubject, instance_token: str):
return self.client.post(
f'group/updateGroupSubject/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def update_group_description(self, instance_id: str, group_jid: str, data: GroupDescription, instance_token: str):
return self.client.post(
f'group/updateGroupDescription/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def get_invite_code(self, instance_id: str, group_jid: str, instance_token: str):
return self.client.get(
f'group/inviteCode/{instance_id}',
params={'groupJid': group_jid},
instance_token=instance_token
)
def revoke_invite_code(self, instance_id: str, group_jid: str, instance_token: str):
return self.client.post(
f'group/revokeInviteCode/{instance_id}',
params={'groupJid': group_jid},
instance_token=instance_token
)
def send_invite(self, instance_id: str, data: GroupInvite, instance_token: str):
return self.client.post(
f'group/sendInvite/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def get_invite_info(self, instance_id: str, invite_code: str, instance_token: str):
return self.client.get(
f'group/inviteInfo/{instance_id}',
params={'inviteCode': invite_code},
instance_token=instance_token
)
def get_group_info(self, instance_id: str, group_jid: str, instance_token: str):
return self.client.get(
f'group/findGroupInfos/{instance_id}',
params={'groupJid': group_jid},
instance_token=instance_token
)
def fetch_all_groups(self, instance_id: str, instance_token: str, get_participants: bool = False):
return self.client.get(
f'group/fetchAllGroups/{instance_id}',
params={'getParticipants': get_participants},
instance_token=instance_token
)
def get_participants(self, instance_id: str, group_jid: str, instance_token: str):
return self.client.get(
f'group/participants/{instance_id}',
params={'groupJid': group_jid},
instance_token=instance_token
)
def update_participant(self, instance_id: str, group_jid: str, data: UpdateParticipant, instance_token: str):
return self.client.post(
f'group/updateParticipant/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def update_setting(self, instance_id: str, group_jid: str, data: UpdateSetting, instance_token: str):
return self.client.post(
f'group/updateSetting/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def toggle_ephemeral(self, instance_id: str, group_jid: str, data: ToggleEphemeral, instance_token: str):
return self.client.post(
f'group/toggleEphemeral/{instance_id}',
params={'groupJid': group_jid},
data=data.__dict__,
instance_token=instance_token
)
def leave_group(self, instance_id: str, group_jid: str, instance_token: str):
return self.client.delete(
f'group/leaveGroup/{instance_id}',
params={'groupJid': group_jid},
instance_token=instance_token
)

View File

@@ -0,0 +1,9 @@
class InstanceService:
def __init__(self, client):
self.client = client
def fetch_instances(self):
return self.client.get('instance/fetchInstances')
def create_instance(self, config):
return self.client.post('instance/create', data=config.__dict__)

View File

@@ -0,0 +1,28 @@
from ..models.presence import PresenceStatus, PresenceConfig
class InstanceOperationsService:
def __init__(self, client):
self.client = client
def connect(self, instance_id: str, instance_token: str):
return self.client.get(f'instance/connect/{instance_id}', instance_token)
def restart(self, instance_id: str, instance_token: str):
return self.client.post(f'instance/restart/{instance_id}', instance_token=instance_token)
def set_presence(self, instance_id: str, presence: PresenceStatus, instance_token: str):
config = PresenceConfig(presence)
return self.client.post(
f'instance/setPresence/{instance_id}',
data=config.__dict__,
instance_token=instance_token
)
def get_connection_state(self, instance_id: str, instance_token: str):
return self.client.get(f'instance/connectionState/{instance_id}', instance_token)
def logout(self, instance_id: str, instance_token: str):
return self.client.delete(f'instance/logout/{instance_id}', instance_token)
def delete(self, instance_id: str, instance_token: str):
return self.client.delete(f'instance/delete/{instance_id}', instance_token)

View File

@@ -0,0 +1,19 @@
from typing import Union, BinaryIO
from ..models.label import *
class LabelService:
def __init__(self, client):
self.client = client
def find_labels(self, instance_id: str, instance_token: str):
return self.client.get(
f'label/findLabels/{instance_id}',
instance_token=instance_token
)
def handle_label(self, instance_id: str, data: HandleLabel, instance_token: str):
return self.client.post(
f'label/handleLabel/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)

View File

@@ -0,0 +1,111 @@
from typing import Union, BinaryIO
from ..models.message import *
class MessageService:
def __init__(self, client):
self.client = client
def send_text(self, instance_id: str, message: TextMessage, instance_token: str):
return self.client.post(
f'message/sendText/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_media(self, instance_id: str, message: MediaMessage, instance_token: str, file: BinaryIO = None):
payload = {
'data': message.__dict__,
'instance_token': instance_token
}
if file:
payload['files'] = {'file': file}
return self.client.post(
f'message/sendMedia/{instance_id}',
**payload
)
def send_ptv(self, instance_id: str, message: dict, instance_token: str, file: BinaryIO = None):
payload = {
'data': message,
'instance_token': instance_token
}
if file:
payload['files'] = {'file': file}
return self.client.post(
f'message/sendPtv/{instance_id}',
**payload
)
def send_whatsapp_audio(self, instance_id: str, message: dict, instance_token: str, file: BinaryIO = None):
payload = {
'data': message,
'instance_token': instance_token
}
if file:
payload['files'] = {'file': file}
return self.client.post(
f'message/sendWhatsAppAudio/{instance_id}',
**payload
)
def send_status(self, instance_id: str, message: StatusMessage, instance_token: str):
return self.client.post(
f'message/sendStatus/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_sticker(self, instance_id: str, message: dict, instance_token: str):
return self.client.post(
f'message/sendSticker/{instance_id}',
data=message,
instance_token=instance_token
)
def send_location(self, instance_id: str, message: LocationMessage, instance_token: str):
return self.client.post(
f'message/sendLocation/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_contact(self, instance_id: str, message: ContactMessage, instance_token: str):
return self.client.post(
f'message/sendContact/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_reaction(self, instance_id: str, message: ReactionMessage, instance_token: str):
return self.client.post(
f'message/sendReaction/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_poll(self, instance_id: str, message: PollMessage, instance_token: str):
return self.client.post(
f'message/sendPoll/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_list(self, instance_id: str, message: ListMessage, instance_token: str):
return self.client.post(
f'message/sendList/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)
def send_buttons(self, instance_id: str, message: ButtonMessage, instance_token: str):
return self.client.post(
f'message/sendButtons/{instance_id}',
data=message.__dict__,
instance_token=instance_token
)

View File

@@ -0,0 +1,60 @@
from typing import Union, BinaryIO
from ..models.profile import *
class ProfileService:
def __init__(self, client):
self.client = client
def fetch_business_profile(self, instance_id: str, data: FetchProfile, instance_token: str):
return self.client.post(
f'chat/fetchBusinessProfile/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def fetch_profile(self, instance_id: str, data: FetchProfile, instance_token: str):
return self.client.post(
f'chat/fetchProfile/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_profile_name(self, instance_id: str, data: ProfileName, instance_token: str):
return self.client.post(
f'chat/updateProfileName/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_profile_status(self, instance_id: str, data: ProfileStatus, instance_token: str):
return self.client.post(
f'chat/updateProfileStatus/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_profile_picture(self, instance_id: str, data: ProfilePicture, instance_token: str):
return self.client.post(
f'chat/updateProfilePicture/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def remove_profile_picture(self, instance_id: str, instance_token: str):
return self.client.delete(
f'chat/removeProfilePicture/{instance_id}',
instance_token=instance_token
)
def fetch_privacy_settings(self, instance_id: str, instance_token: str):
return self.client.get(
f'chat/fetchPrivacySettings/{instance_id}',
instance_token=instance_token
)
def update_privacy_settings(self, instance_id: str, data: PrivacySettings, instance_token: str):
return self.client.post(
f'chat/updatePrivacySettings/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)