{"id":48830638,"url":"https://github.com/evolutionapi/evolution-client-python","last_synced_at":"2026-04-14T20:03:12.665Z","repository":{"id":260299734,"uuid":"880874407","full_name":"EvolutionAPI/evolution-client-python","owner":"EvolutionAPI","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-06T17:33:30.000Z","size":16578,"stargazers_count":64,"open_issues_count":7,"forks_count":19,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-01T22:24:23.139Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EvolutionAPI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-30T14:18:52.000Z","updated_at":"2025-10-27T20:02:05.000Z","dependencies_parsed_at":"2024-12-11T21:28:43.632Z","dependency_job_id":null,"html_url":"https://github.com/EvolutionAPI/evolution-client-python","commit_stats":null,"previous_names":["evolutionapi/evolution-client-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EvolutionAPI/evolution-client-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvolutionAPI%2Fevolution-client-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvolutionAPI%2Fevolution-client-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvolutionAPI%2Fevolution-client-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvolutionAPI%2Fevolution-client-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvolutionAPI","download_url":"https://codeload.github.com/EvolutionAPI/evolution-client-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvolutionAPI%2Fevolution-client-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31812977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-14T20:03:02.232Z","updated_at":"2026-04-14T20:03:12.652Z","avatar_url":"https://github.com/EvolutionAPI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Evolution Client Python\n\nPython client to interact with the evolutionapi.\n\n## Installation\n\n```bash\npip install evolutionapi\n```\n\n## Basic Usage\n\n### Initializing the Client\n\n```python\nfrom evolutionapi.client import EvolutionClient\n\nclient = EvolutionClient(\n    base_url='http://your-server:port',\n    api_token='your-api-token'\n)\n```\n\n### Instance Management\n\n#### List Instances\n\n```python\ninstances = client.instances.fetch_instances()\n```\n\n#### Create New Instance\n\n```python\nfrom evolutionapi.models.instance import InstanceConfig\n\n# Configuração básica\nconfig = InstanceConfig(\n    instanceName=\"minha-instancia\",\n    integration=\"WHATSAPP-BAILEYS\",\n    qrcode=True\n)\n\n# Configuração completa\nconfig = InstanceConfig(\n    instanceName=\"minha-instancia\",\n    integration=\"WHATSAPP-BAILEYS\",\n    token=\"token_da_instancia\",\n    number=\"5511999999999\",\n    qrcode=True,\n    rejectCall=True,\n    msgCall=\"Mensagem de chamada rejeitada\",\n    groupsIgnore=True,\n    alwaysOnline=True,\n    readMessages=True,\n    readStatus=True,\n    syncFullHistory=True\n)\n\nnew_instance = client.instances.create_instance(config)\n```\n\n#### Configure Webhook\n\n```python\nfrom evolutionapi.models.instance import WebhookConfig\n\nconfig = WebhookConfig(\n    url=\"https://seu-servidor.com/webhook\",\n    byEvents=True,\n    base64=True,\n    headers={\n        \"Authorization\": \"Bearer seu-token\"\n    },\n    events=[\n        \"messages.upsert\",\n        \"messages.update\",\n        \"messages.delete\",\n        \"groups.upsert\",\n        \"groups.update\",\n        \"groups.delete\",\n        \"group-participants.update\",\n        \"contacts.upsert\",\n        \"contacts.update\",\n        \"contacts.delete\",\n        \"presence.update\",\n        \"chats.upsert\",\n        \"chats.update\",\n        \"chats.delete\",\n        \"call\"\n    ]\n)\n\nresponse = client.instances.set_webhook(instance_id, config, instance_token)\n```\n\n#### Configure Events\n\n```python\nfrom evolutionapi.models.instance import EventsConfig\n\nconfig = EventsConfig(\n    enabled=True,\n    events=[\n        \"messages.upsert\",\n        \"messages.update\",\n        \"messages.delete\",\n        \"groups.upsert\",\n        \"groups.update\",\n        \"groups.delete\",\n        \"group-participants.update\",\n        \"contacts.upsert\",\n        \"contacts.update\",\n        \"contacts.delete\",\n        \"presence.update\",\n        \"chats.upsert\",\n        \"chats.update\",\n        \"chats.delete\",\n        \"call\"\n    ]\n)\n\nresponse = client.instances.set_events(instance_id, config, instance_token)\n```\n\n#### Configure Chatwoot Integration\n\n```python\nfrom evolutionapi.models.instance import ChatwootConfig\n\nconfig = ChatwootConfig(\n    accountId=\"seu-account-id\",\n    token=\"seu-token\",\n    url=\"https://seu-chatwoot.com\",\n    signMsg=True,\n    reopenConversation=True,\n    conversationPending=False,\n    importContacts=True,\n    nameInbox=\"evolution\",\n    mergeBrazilContacts=True,\n    importMessages=True,\n    daysLimitImportMessages=3,\n    organization=\"Evolution Bot\",\n    logo=\"https://evolution-api.com/files/evolution-api-favicon.png\"\n)\n\nresponse = client.instances.set_chatwoot(instance_id, config, instance_token)\n```\n\n#### Delete Instance\n\n```python\nresponse = client.instances.delete_instance(instance_id, instance_token)\n```\n\n#### Get Instance Info\n\n```python\nresponse = client.instances.get_instance_info(instance_id, instance_token)\n```\n\n#### Get Instance QR Code\n\n```python\nresponse = client.instances.get_instance_qrcode(instance_id, instance_token)\n```\n\n#### Get Instance Status\n\n```python\nresponse = client.instances.get_instance_status(instance_id, instance_token)\n```\n\n#### Logout Instance\n\n```python\nresponse = client.instances.logout_instance(instance_id, instance_token)\n```\n\n#### Restart Instance\n\n```python\nresponse = client.instances.restart_instance(instance_id, instance_token)\n```\n\n### Instance Operations\n\n#### Connect Instance\n\n```python\nstate = client.instance_operations.connect(instance_id, instance_token)\n```\n\n#### Check Connection State\n\n```python\nstate = client.instance_operations.get_connection_state(instance_id, instance_token)\n```\n\n#### Set Presence\n\n```python\nfrom evolutionapi.models.presence import PresenceConfig, PresenceStatus\n\n# Definir como disponível\nconfig = PresenceConfig(\n    presence=PresenceStatus.AVAILABLE\n)\n\n# Definir como indisponível\nconfig = PresenceConfig(\n    presence=PresenceStatus.UNAVAILABLE\n)\n\nresponse = client.instance_operations.set_presence(instance_id, config, instance_token)\n```\n\n### Sending Messages\n\n#### Text Message\n\n```python\nfrom evolutionapi.models.message import TextMessage, QuotedMessage\n\n# Mensagem simples\nmessage = TextMessage(\n    number=\"5511999999999\",\n    text=\"Olá, como você está?\",\n    delay=1000  # delay opcional em ms\n)\n\n# Mensagem com menções\nmessage = TextMessage(\n    number=\"5511999999999\",\n    text=\"@everyone Olá a todos!\",\n    mentionsEveryOne=True,\n    mentioned=[\"5511999999999\", \"5511888888888\"]\n)\n\n# Mensagem com link preview\nmessage = TextMessage(\n    number=\"5511999999999\",\n    text=\"Confira este link: https://exemplo.com\",\n    linkPreview=True\n)\n\n# Mensagem com citação\nquoted = QuotedMessage(\n    key={\n        \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n        \"fromMe\": False,\n        \"participant\": \"5511999999999@s.whatsapp.net\",\n        \"id\": \"123456789\",\n        \"owner\": \"5511999999999@s.whatsapp.net\"\n    }\n)\n\nmessage = TextMessage(\n    number=\"5511999999999\",\n    text=\"Esta é uma resposta\",\n    quoted=quoted\n)\n\nresponse = client.messages.send_text(instance_id, message, instance_token)\n```\n\n#### Media Message\n\n```python\nfrom evolutionapi.models.message import MediaMessage, MediaType, QuotedMessage\n\n# Mensagem com imagem\nmessage = MediaMessage(\n    number=\"5511999999999\",\n    mediatype=MediaType.IMAGE.value,\n    mimetype=\"image/jpeg\",\n    caption=\"Minha imagem\",\n    media=\"base64_da_imagem_ou_url\",\n    fileName=\"imagem.jpg\",\n    delay=1000  # delay opcional\n)\n\n# Mensagem com vídeo\nmessage = MediaMessage(\n    number=\"5511999999999\",\n    mediatype=MediaType.VIDEO.value,\n    mimetype=\"video/mp4\",\n    caption=\"Meu vídeo\",\n    media=\"base64_do_video_ou_url\",\n    fileName=\"video.mp4\"\n)\n\n# Mensagem com documento\nmessage = MediaMessage(\n    number=\"5511999999999\",\n    mediatype=MediaType.DOCUMENT.value,\n    mimetype=\"application/pdf\",\n    caption=\"Meu documento\",\n    media=\"base64_do_documento_ou_url\",\n    fileName=\"documento.pdf\"\n)\n\n# Mensagem com menções\nmessage = MediaMessage(\n    number=\"5511999999999\",\n    mediatype=MediaType.IMAGE.value,\n    mimetype=\"image/jpeg\",\n    caption=\"@everyone Olhem esta imagem!\",\n    media=\"base64_da_imagem\",\n    mentionsEveryOne=True,\n    mentioned=[\"5511999999999\", \"5511888888888\"]\n)\n\nresponse = client.messages.send_media(instance_id, message, instance_token)\n```\n\n#### Status Message\n\n```python\nfrom evolutionapi.models.message import StatusMessage, StatusType, FontType\n\n# Status de texto\nmessage = StatusMessage(\n    type=StatusType.TEXT,\n    content=\"Meu status de texto\",\n    caption=\"Legenda opcional\",\n    backgroundColor=\"#FF0000\",\n    font=FontType.BEBASNEUE_REGULAR,\n    allContacts=True\n)\n\n# Status de imagem\nmessage = StatusMessage(\n    type=StatusType.IMAGE,\n    content=\"base64_da_imagem\",\n    caption=\"Minha imagem de status\"\n)\n\n# Status de vídeo\nmessage = StatusMessage(\n    type=StatusType.VIDEO,\n    content=\"base64_do_video\",\n    caption=\"Meu vídeo de status\"\n)\n\n# Status de áudio\nmessage = StatusMessage(\n    type=StatusType.AUDIO,\n    content=\"base64_do_audio\",\n    caption=\"Meu áudio de status\"\n)\n\nresponse = client.messages.send_status(instance_id, message, instance_token)\n```\n\n#### Location Message\n\n```python\nfrom evolutionapi.models.message import LocationMessage\n\nmessage = LocationMessage(\n    number=\"5511999999999\",\n    name=\"Localização\",\n    address=\"Endereço completo\",\n    latitude=-23.550520,\n    longitude=-46.633308,\n    delay=1000  # delay opcional\n)\n\nresponse = client.messages.send_location(instance_id, message, instance_token)\n```\n\n#### Contact Message\n\n```python\nfrom evolutionapi.models.message import ContactMessage, Contact\n\ncontact = Contact(\n    fullName=\"Nome Completo\",\n    wuid=\"5511999999999\",\n    phoneNumber=\"5511999999999\",\n    organization=\"Empresa\",\n    email=\"email@exemplo.com\",\n    url=\"https://exemplo.com\"\n)\n\nmessage = ContactMessage(\n    number=\"5511999999999\",\n    contact=[contact]\n)\n\nresponse = client.messages.send_contact(instance_id, message, instance_token)\n```\n\n#### Reaction Message\n\n```python\nfrom evolutionapi.models.message import ReactionMessage\n\nmessage = ReactionMessage(\n    key={\n        \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n        \"fromMe\": False,\n        \"participant\": \"5511999999999@s.whatsapp.net\",\n        \"id\": \"123456789\",\n        \"owner\": \"5511999999999@s.whatsapp.net\"\n    },\n    reaction=\"👍\"\n)\n\nresponse = client.messages.send_reaction(instance_id, message, instance_token)\n```\n\n#### Poll Message\n\n```python\nfrom evolutionapi.models.message import PollMessage\n\nmessage = PollMessage(\n    number=\"5511999999999\",\n    name=\"Minha Enquete\",\n    selectableCount=1,  # número de opções que podem ser selecionadas\n    values=[\"Opção 1\", \"Opção 2\", \"Opção 3\"],\n    delay=1000  # delay opcional\n)\n\nresponse = client.messages.send_poll(instance_id, message, instance_token)\n```\n\n#### Button Message\n\n```python\nfrom evolutionapi.models.message import ButtonMessage, Button\n\n# Botão de resposta simples\nbuttons = [\n    Button(\n        type=\"reply\",\n        displayText=\"Opção 1\",\n        id=\"1\"\n    ),\n    Button(\n        type=\"reply\",\n        displayText=\"Opção 2\",\n        id=\"2\"\n    )\n]\n\n# Botão com URL\nbuttons = [\n    Button(\n        type=\"url\",\n        displayText=\"Visitar Site\",\n        url=\"https://exemplo.com\"\n    )\n]\n\n# Botão com número de telefone\nbuttons = [\n    Button(\n        type=\"phoneNumber\",\n        displayText=\"Ligar\",\n        phoneNumber=\"5511999999999\"\n    )\n]\n\n# Botão com código de cópia\nbuttons = [\n    Button(\n        type=\"copyCode\",\n        displayText=\"Copiar Código\",\n        copyCode=\"ABC123\"\n    )\n]\n\nmessage = ButtonMessage(\n    number=\"5511999999999\",\n    title=\"Título\",\n    description=\"Descrição\",\n    footer=\"Rodapé\",\n    buttons=buttons,\n    delay=1000  # delay opcional\n)\n\nresponse = client.messages.send_buttons(instance_id, message, instance_token)\n```\n\n#### List Message\n\n```python\nfrom evolutionapi.models.message import ListMessage, ListSection, ListRow\n\nrows = [\n    ListRow(\n        title=\"Item 1\",\n        description=\"Descrição do item 1\",\n        rowId=\"1\"\n    ),\n    ListRow(\n        title=\"Item 2\",\n        description=\"Descrição do item 2\",\n        rowId=\"2\"\n    )\n]\n\nsection = ListSection(\n    title=\"Seção 1\",\n    rows=rows\n)\n\nmessage = ListMessage(\n    number=\"5511999999999\",\n    title=\"Título da Lista\",\n    description=\"Descrição da lista\",\n    buttonText=\"Clique aqui\",\n    footerText=\"Rodapé\",\n    sections=[section],\n    delay=1000  # delay opcional\n)\n\nresponse = client.messages.send_list(instance_id, message, instance_token)\n```\n\n### Group Management\n\n#### Create Group\n\n```python\nfrom evolutionapi.models.group import CreateGroup\n\nconfig = CreateGroup(\n    subject=\"Nome do Grupo\",\n    participants=[\"5511999999999\", \"5511888888888\"],\n    description=\"Descrição do grupo\"\n)\n\nresponse = client.group.create_group(instance_id, config, instance_token)\n```\n\n#### Update Group Picture\n\n```python\nfrom evolutionapi.models.group import GroupPicture\n\nconfig = GroupPicture(\n    image=\"base64_da_imagem\"\n)\n\nresponse = client.group.update_group_picture(instance_id, \"group_jid\", config, instance_token)\n```\n\n#### Update Group Subject\n\n```python\nfrom evolutionapi.models.group import GroupSubject\n\nconfig = GroupSubject(\n    subject=\"Novo Nome do Grupo\"\n)\n\nresponse = client.group.update_group_subject(instance_id, \"group_jid\", config, instance_token)\n```\n\n#### Update Group Description\n\n```python\nfrom evolutionapi.models.group import GroupDescription\n\nconfig = GroupDescription(\n    description=\"Nova descrição do grupo\"\n)\n\nresponse = client.group.update_group_description(instance_id, \"group_jid\", config, instance_token)\n```\n\n#### Send Group Invite\n\n```python\nfrom evolutionapi.models.group import GroupInvite\n\nconfig = GroupInvite(\n    groupJid=\"group_jid\",\n    description=\"Convite para o grupo\",\n    numbers=[\"5511999999999\", \"5511888888888\"]\n)\n\nresponse = client.group.send_group_invite(instance_id, config, instance_token)\n```\n\n#### Manage Participants\n\n```python\nfrom evolutionapi.models.group import UpdateParticipant\n\n# Adicionar participantes\nconfig = UpdateParticipant(\n    action=\"add\",\n    participants=[\"5511999999999\", \"5511888888888\"]\n)\n\n# Remover participantes\nconfig = UpdateParticipant(\n    action=\"remove\",\n    participants=[\"5511999999999\"]\n)\n\n# Promover a administrador\nconfig = UpdateParticipant(\n    action=\"promote\",\n    participants=[\"5511999999999\"]\n)\n\n# Rebaixar de administrador\nconfig = UpdateParticipant(\n    action=\"demote\",\n    participants=[\"5511999999999\"]\n)\n\nresponse = client.group.update_participant(instance_id, \"group_jid\", config, instance_token)\n```\n\n#### Update Group Settings\n\n```python\nfrom evolutionapi.models.group import UpdateSetting\n\n# Ativar modo anúncio\nconfig = UpdateSetting(\n    action=\"announcement\"\n)\n\n# Desativar modo anúncio\nconfig = UpdateSetting(\n    action=\"not_announcement\"\n)\n\n# Bloquear grupo\nconfig = UpdateSetting(\n    action=\"locked\"\n)\n\n# Desbloquear grupo\nconfig = UpdateSetting(\n    action=\"unlocked\"\n)\n\nresponse = client.group.update_setting(instance_id, \"group_jid\", config, instance_token)\n```\n\n#### Toggle Ephemeral Messages\n\n```python\nfrom evolutionapi.models.group import ToggleEphemeral\n\nconfig = ToggleEphemeral(\n    expiration=86400  # 24 horas em segundos\n)\n\nresponse = client.group.toggle_ephemeral(instance_id, \"group_jid\", config, instance_token)\n```\n\n### Profile Management\n\n#### Fetch Profile\n\n```python\nfrom evolutionapi.models.profile import FetchProfile\n\nconfig = FetchProfile(\n    number=\"5511999999999\"\n)\n\nresponse = client.profile.fetch_profile(instance_id, config, instance_token)\n```\n\n#### Update Profile Name\n\n```python\nfrom evolutionapi.models.profile import ProfileName\n\nconfig = ProfileName(\n    name=\"Novo Nome\"\n)\n\nresponse = client.profile.update_profile_name(instance_id, config, instance_token)\n```\n\n#### Update Status\n\n```python\nfrom evolutionapi.models.profile import ProfileStatus\n\nconfig = ProfileStatus(\n    status=\"Novo status\"\n)\n\nresponse = client.profile.update_profile_status(instance_id, config, instance_token)\n```\n\n#### Update Profile Picture\n\n```python\nfrom evolutionapi.models.profile import ProfilePicture\n\nconfig = ProfilePicture(\n    picture=\"base64_da_imagem\"\n)\n\nresponse = client.profile.update_profile_picture(instance_id, config, instance_token)\n```\n\n#### Configure Privacy Settings\n\n```python\nfrom evolutionapi.models.profile import PrivacySettings\n\nconfig = PrivacySettings(\n    readreceipts=\"all\",           # \"all\" ou \"none\"\n    profile=\"contacts\",           # \"all\", \"contacts\", \"contact_blacklist\" ou \"none\"\n    status=\"contacts\",            # \"all\", \"contacts\", \"contact_blacklist\" ou \"none\"\n    online=\"all\",                 # \"all\" ou \"match_last_seen\"\n    last=\"contacts\",              # \"all\", \"contacts\", \"contact_blacklist\" ou \"none\"\n    groupadd=\"contacts\"           # \"all\", \"contacts\" ou \"contact_blacklist\"\n)\n\nresponse = client.profile.update_privacy_settings(instance_id, config, instance_token)\n```\n\n### Chat Operations\n\n#### Check WhatsApp Numbers\n\n```python\nfrom evolutionapi.models.chat import CheckIsWhatsappNumber\n\nconfig = CheckIsWhatsappNumber(\n    numbers=[\"5511999999999\", \"5511888888888\"]\n)\n\nresponse = client.chat.check_is_whatsapp_numbers(instance_id, config, instance_token)\n```\n\n#### Mark Message as Read\n\n```python\nfrom evolutionapi.models.chat import ReadMessage\n\nmessage = ReadMessage(\n    remote_jid=\"5511999999999@s.whatsapp.net\",\n    from_me=False,\n    id=\"message_id\"\n)\n\nresponse = client.chat.mark_message_as_read(instance_id, [message], instance_token)\n```\n\n#### Archive Chat\n\n```python\nfrom evolutionapi.models.chat import ArchiveChat\n\nconfig = ArchiveChat(\n    last_message={\n        \"key\": {\n            \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n            \"fromMe\": False,\n            \"id\": \"message_id\",\n            \"participant\": \"5511999999999@s.whatsapp.net\"\n        },\n        \"message\": {\n            \"conversation\": \"Última mensagem\"\n        }\n    },\n    chat=\"5511999999999@s.whatsapp.net\",\n    archive=True  # True para arquivar, False para desarquivar\n)\n\nresponse = client.chat.archive_chat(instance_id, config, instance_token)\n```\n\n#### Mark Chat as Unread\n\n```python\nfrom evolutionapi.models.chat import UnreadChat\n\nconfig = UnreadChat(\n    last_message={\n        \"key\": {\n            \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n            \"fromMe\": False,\n            \"id\": \"message_id\",\n            \"participant\": \"5511999999999@s.whatsapp.net\"\n        },\n        \"message\": {\n            \"conversation\": \"Última mensagem\"\n        }\n    },\n    chat=\"5511999999999@s.whatsapp.net\"\n)\n\nresponse = client.chat.unread_chat(instance_id, config, instance_token)\n```\n\n#### Get Chat Profile Picture\n\n```python\nfrom evolutionapi.models.chat import ProfilePicture\n\nconfig = ProfilePicture(\n    number=\"5511999999999\"\n)\n\nresponse = client.chat.get_chat_profile_picture(instance_id, config, instance_token)\n```\n\n#### Download Media Message\n\n```python\nfrom evolutionapi.models.chat import MediaMessage\n\nconfig = MediaMessage(\n    message={\n        \"key\": {\n            \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n            \"fromMe\": False,\n            \"id\": \"message_id\",\n            \"participant\": \"5511999999999@s.whatsapp.net\"\n        },\n        \"message\": {\n            \"imageMessage\": {\n                \"jpegThumbnail\": \"base64_da_imagem\"\n            }\n        }\n    },\n    convert_to_mp4=True  # opcional, para converter vídeos para MP4\n)\n\nresponse = client.chat.download_media_message(instance_id, config, instance_token)\n```\n\n#### Update Message\n\n```python\nfrom evolutionapi.models.chat import UpdateMessage\n\nconfig = UpdateMessage(\n    number=\"5511999999999\",\n    key={\n        \"remoteJid\": \"5511999999999@s.whatsapp.net\",\n        \"fromMe\": False,\n        \"id\": \"message_id\",\n        \"participant\": \"5511999999999@s.whatsapp.net\"\n    },\n    text=\"Mensagem atualizada\"\n)\n\nresponse = client.chat.update_message(instance_id, config, instance_token)\n```\n\n#### Set Presence\n\n```python\nfrom evolutionapi.models.chat import Presence\n\nconfig = Presence(\n    number=\"5511999999999\",\n    delay=1000,  # delay em ms\n    presence=\"composing\"  # \"composing\", \"recording\", \"paused\"\n)\n\nresponse = client.chat.set_presence(instance_id, config, instance_token)\n```\n\n### Calls\n\n#### Simulate Call\n\n```python\nfrom evolutionapi.models.call import FakeCall\n\n# Chamada de voz\nconfig = FakeCall(\n    number=\"5511999999999\",\n    isVideo=False,\n    callDuration=30  # duração em segundos\n)\n\n# Chamada de vídeo\nconfig = FakeCall(\n    number=\"5511999999999\",\n    isVideo=True,\n    callDuration=30  # duração em segundos\n)\n\nresponse = client.calls.fake_call(instance_id, config, instance_token)\n```\n\n### Labels\n\n#### Manage Labels\n\n```python\nfrom evolutionapi.models.label import HandleLabel\n\n# Adicionar etiqueta\nconfig = HandleLabel(\n    number=\"5511999999999\",\n    label_id=\"label_id\",\n    action=\"add\"\n)\n\n# Remover etiqueta\nconfig = HandleLabel(\n    number=\"5511999999999\",\n    label_id=\"label_id\",\n    action=\"remove\"\n)\n\nresponse = client.label.handle_label(instance_id, config, instance_token)\n```\n\n## WebSocket\n\nThe Evolution API client supports WebSocket connection to receive real-time events. Here's a guide on how to use it:\n\n### Prerequisites\n\nBefore using WebSocket, you need to:\n\n1. Enable WebSocket in your Evolution API by setting the environment variable:\n\n```bash\nWEBSOCKET_ENABLED=true\n```\n\n2. Configure WebSocket events for your instance using the WebSocket service:\n\n```python\nfrom evolutionapi.models.websocket import WebSocketConfig\n\n# Configure WebSocket events\nconfig = WebSocketConfig(\n    enabled=True,\n    events=[\n        \"APPLICATION_STARTUP\",\n        \"QRCODE_UPDATED\",\n        \"MESSAGES_SET\",\n        \"MESSAGES_UPSERT\",\n        \"MESSAGES_UPDATE\",\n        \"MESSAGES_DELETE\",\n        \"SEND_MESSAGE\",\n        \"CONTACTS_SET\",\n        \"CONTACTS_UPSERT\",\n        \"CONTACTS_UPDATE\",\n        \"PRESENCE_UPDATE\",\n        \"CHATS_SET\",\n        \"CHATS_UPSERT\",\n        \"CHATS_UPDATE\",\n        \"CHATS_DELETE\",\n        \"GROUPS_UPSERT\",\n        \"GROUP_UPDATE\",\n        \"GROUP_PARTICIPANTS_UPDATE\",\n        \"CONNECTION_UPDATE\",\n        \"LABELS_EDIT\",\n        \"LABELS_ASSOCIATION\",\n        \"CALL\",\n        \"TYPEBOT_START\",\n        \"TYPEBOT_CHANGE_STATUS\"\n    ]\n)\n\n# Set WebSocket configuration\nresponse = client.websocket.set_websocket(instance_id, config, instance_token)\n\n# Get current WebSocket configuration\nwebsocket_info = client.websocket.find_websocket(instance_id, instance_token)\nprint(f\"WebSocket enabled: {websocket_info.enabled}\")\nprint(f\"Configured events: {websocket_info.events}\")\n```\n\n### Basic Configuration\n\nThere are two ways to create a WebSocket manager:\n\n1. Using the client's helper method (recommended):\n\n```python\n# Create WebSocket manager using the client\nwebsocket = client.create_websocket(\n    instance_id=\"test\",\n    api_token=\"your_api_token\",\n    max_retries=5,        # Maximum number of reconnection attempts\n    retry_delay=1.0       # Initial delay between attempts in seconds\n)\n```\n\n2. Creating the manager directly:\n\n```python\nfrom evolutionapi.client import EvolutionClient\nimport logging\n\n# Logging configuration\nlogging.basicConfig(\n    level=logging.INFO,\n    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n)\n\n# Initialize client\nclient = EvolutionClient(\n    base_url=\"http://localhost:8081\",\n    api_token=\"your-api-token\"\n)\n\n# Create WebSocket manager\nwebsocket = client.create_websocket(\n    instance_id=\"test\",\n    api_token=\"your_api_token\",\n    max_retries=5,\n    retry_delay=1.0\n)\n```\n\n### Registering Event Handlers\n\nYou can register handlers for different types of events:\n\n```python\ndef handle_message(data):\n    print(f\"New message received: {data}\")\n\ndef handle_qrcode(data):\n    print(f\"QR Code updated: {data}\")\n\n# Registering handlers\nwebsocket.on(\"messages.upsert\", handle_message)\nwebsocket.on(\"qrcode.updated\", handle_qrcode)\n```\n\n### Available Events\n\nThe available events are:\n\n#### Instance Events\n\n- `application.startup`: Triggered when the application starts\n- `instance.create`: Triggered when a new instance is created\n- `instance.delete`: Triggered when an instance is deleted\n- `remove.instance`: Triggered when an instance is removed\n- `logout.instance`: Triggered when an instance logs out\n\n#### Connection and QR Code Events\n\n- `qrcode.updated`: Triggered when the QR Code is updated\n- `connection.update`: Triggered when connection status changes\n- `status.instance`: Triggered when instance status changes\n- `creds.update`: Triggered when credentials are updated\n\n#### Message Events\n\n- `messages.set`: Triggered when messages are set\n- `messages.upsert`: Triggered when new messages are received\n- `messages.edited`: Triggered when messages are edited\n- `messages.update`: Triggered when messages are updated\n- `messages.delete`: Triggered when messages are deleted\n- `send.message`: Triggered when a message is sent\n- `messaging-history.set`: Triggered when messaging history is set\n\n#### Contact Events\n\n- `contacts.set`: Triggered when contacts are set\n- `contacts.upsert`: Triggered when new contacts are added\n- `contacts.update`: Triggered when contacts are updated\n\n#### Chat Events\n\n- `chats.set`: Triggered when chats are set\n- `chats.update`: Triggered when chats are updated\n- `chats.upsert`: Triggered when new chats are added\n- `chats.delete`: Triggered when chats are deleted\n\n#### Group Events\n\n- `groups.upsert`: Triggered when groups are created/updated\n- `groups.update`: Triggered when groups are updated\n- `group-participants.update`: Triggered when group participants are updated\n\n#### Presence Events\n\n- `presence.update`: Triggered when presence status is updated\n\n#### Call Events\n\n- `call`: Triggered when there's a call\n\n#### Typebot Events\n\n- `typebot.start`: Triggered when a typebot starts\n- `typebot.change-status`: Triggered when typebot status changes\n\n#### Label Events\n\n- `labels.edit`: Triggered when labels are edited\n- `labels.association`: Triggered when labels are associated/disassociated\n\n### Example with Specific Events\n\n```python\ndef handle_messages(data):\n    logger.info(f\"New message: {data}\")\n\ndef handle_contacts(data):\n    logger.info(f\"Contacts updated: {data}\")\n\ndef handle_groups(data):\n    logger.info(f\"Groups updated: {data}\")\n\ndef handle_presence(data):\n    logger.info(f\"Presence status: {data}\")\n\n# Registering handlers for different events\nwebsocket.on(\"messages.upsert\", handle_messages)\nwebsocket.on(\"contacts.upsert\", handle_contacts)\nwebsocket.on(\"groups.upsert\", handle_groups)\nwebsocket.on(\"presence.update\", handle_presence)\n```\n\n### Complete Example\n\n```python\nfrom evolutionapi.client import EvolutionClient\nfrom evolutionapi.models.websocket import WebSocketConfig\nimport logging\nimport time\n\n# Logging configuration\nlogging.basicConfig(\n    level=logging.INFO,\n    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n)\nlogger = logging.getLogger(__name__)\n\ndef handle_message(data):\n    logger.info(f\"New message received: {data}\")\n\ndef handle_qrcode(data):\n    logger.info(f\"QR Code updated: {data}\")\n\ndef handle_connection(data):\n    logger.info(f\"Connection status: {data}\")\n\ndef main():\n    # Initialize client\n    client = EvolutionClient(\n        base_url=\"http://localhost:8081\",\n        api_token=\"your-api-token\"\n    )\n\n    # Configure WebSocket\n    websocket_config = WebSocketConfig(\n        enabled=True,\n        events=[\n            \"MESSAGES_UPSERT\",\n            \"QRCODE_UPDATED\",\n            \"CONNECTION_UPDATE\"\n        ]\n    )\n\n    # Set WebSocket configuration\n    client.websocket.set_websocket(\"instance_id\", websocket_config, \"instance_token\")\n\n    # Create WebSocket manager\n    websocket = client.create_websocket(\n        instance_id=\"instance_id\",\n        api_token=\"your_api_token\",\n        max_retries=5,\n        retry_delay=1.0\n    )\n\n    # Register handlers\n    websocket.on(\"messages.upsert\", handle_message)\n    websocket.on(\"qrcode.updated\", handle_qrcode)\n    websocket.on(\"connection.update\", handle_connection)\n\n    try:\n        # Connect to WebSocket\n        websocket.connect()\n        logger.info(\"Connected to WebSocket. Waiting for events...\")\n\n        # Keep the program running\n        while True:\n            time.sleep(1)\n\n    except KeyboardInterrupt:\n        logger.info(\"Closing connection...\")\n        websocket.disconnect()\n    except Exception as e:\n        logger.error(f\"Error: {e}\")\n        websocket.disconnect()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Additional Features\n\n#### Automatic Reconnection\n\nThe WebSocket Manager has automatic reconnection with exponential backoff:\n\n```python\nwebsocket = client.create_websocket(\n    instance_id=\"test\",\n    api_token=\"your_api_token\",\n    max_retries=5,        # Maximum number of reconnection attempts\n    retry_delay=1.0       # Initial delay between attempts in seconds\n)\n```\n\n#### Logging\n\nThe WebSocket Manager uses Python's logging system. You can adjust the log level as needed:\n\n```python\n# For more details\nlogging.getLogger(\"evolutionapi.services.websocket\").setLevel(logging.DEBUG)\n```\n\n### Error Handling\n\nThe WebSocket Manager has robust error handling:\n\n- Automatic reconnection on disconnection\n- Detailed error logs\n- Invalid event handling\n- Data validation\n\n### Usage Tips\n\n1. Always use try/except when connecting to WebSocket\n2. Implement handlers for all events you need to monitor\n3. Use logging for debugging and monitoring\n4. Consider implementing a heartbeat mechanism if needed\n5. Keep your API token secure and don't expose it in logs\n6. Keep your API token secure and don't expose it in logs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolutionapi%2Fevolution-client-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevolutionapi%2Fevolution-client-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolutionapi%2Fevolution-client-python/lists"}