Current section
Files
Jump to
Current section
Files
lib/api_brasil/messaging/whats_app.ex
defmodule ApiBrasil.Messaging.WhatsApp do
@moduledoc """
API de WhatsApp (device-based): `POST /whatsapp/{action}`.
Exige `Authorization: Bearer` + header `DeviceToken`.
client = ApiBrasil.new(bearer_token: "...", device_token: "...")
# inicia a sessão do device (os webhooks são opcionais)
{:ok, _envelope} =
ApiBrasil.Messaging.WhatsApp.start(client, %{
"webhook_wh_message" => "https://exemplo.com/hook"
})
# QR Code de pareamento — o base64 vem em `response.qrcode`
{:ok, qr} = ApiBrasil.Messaging.WhatsApp.qrcode(client)
ApiBrasil.Core.DeviceResponse.response(qr)
{:ok, _envelope} =
ApiBrasil.Messaging.WhatsApp.send_text(client, %{
"number" => "5511999999999",
"text" => "Olá!"
})
# qualquer action do catálogo, e a mesma action por fila
ApiBrasil.Messaging.WhatsApp.request(client, "getAllChats")
ApiBrasil.Messaging.WhatsApp.queue(client, "sendText", %{
"number" => "5511999999999",
"text" => "por fila"
})
As actions conhecidas estão em
`ApiBrasil.Generated.Catalog.service_actions("whatsapp")`; a documentação
completa fica em <https://doc.apibrasil.io>.
"""
use ApiBrasil.Core.Service, device: "whatsapp"
action(
:start,
"start",
"""
Inicia a sessão do device: `POST /whatsapp/start`.
Aceita os webhooks opcionais `webhook_wh_status`, `webhook_wh_message`,
`webhook_wh_connect` e `webhook_wh_qrcode`.
"""
)
action(:qrcode, "qrcode", "QR Code de pareamento em base64: `POST /whatsapp/qrcode`.")
action(:logout, "logout", "Encerra a sessão: `POST /whatsapp/logout`.")
action(:close, "close", "Fecha o navegador/sessão no servidor: `POST /whatsapp/close`.")
action(
:delete_session,
"deleteSession",
"Apaga a sessão no servidor: `POST /whatsapp/deleteSession`."
)
action(
:restart_session,
"restartSession",
"Reinicia a sessão do device: `POST /whatsapp/restartSession`."
)
action(
:get_connection_status,
"getConnectionStatus",
"Status da conexão do device: `POST /whatsapp/getConnectionStatus`."
)
action(
:send_text,
"sendText",
"""
Envia uma mensagem de texto: `POST /whatsapp/sendText`.
%{"number" => "5511999999999", "text" => "Olá!"}
"""
)
action(
:send_file,
"sendFile",
"Envia um arquivo a partir de uma URL (`number`, `path`): `POST /whatsapp/sendFile`."
)
action(:send_file64, "sendFile64", "Envia um arquivo em base64: `POST /whatsapp/sendFile64`.")
action(
:send_audio,
"sendAudio",
"""
Envia áudio por URL: `POST /whatsapp/sendAudio`.
O gateway converte o arquivo para mp3 (duração máxima de 6 minutos).
"""
)
action(:send_video, "sendVideo", "Envia um vídeo por URL: `POST /whatsapp/sendVideo`.")
action(:send_gif, "sendGif", "Envia um GIF: `POST /whatsapp/sendGif`.")
action(:send_link, "sendLink", "Envia um link com preview: `POST /whatsapp/sendLink`.")
action(
:send_location,
"sendLocation",
"Envia uma localização (`number`, `lat`, `lng`): `POST /whatsapp/sendLocation`."
)
action(:send_contact, "sendContact", "Envia um contato: `POST /whatsapp/sendContact`.")
action(:send_sticker, "sendSticker", "Envia uma figurinha: `POST /whatsapp/sendSticker`.")
action(:send_list, "sendList", "Envia uma mensagem de lista: `POST /whatsapp/sendList`.")
action(
:send_buttons,
"sendButtons",
"Envia uma mensagem com botões: `POST /whatsapp/sendButtons`."
)
action(
:send_poll_message,
"sendPollMessage",
"Envia uma enquete: `POST /whatsapp/sendPollMessage`."
)
action(:send_pix_key, "sendPixKey", "Envia uma chave PIX: `POST /whatsapp/sendPixKey`.")
action(
:send_text_to_storie,
"sendTextToStorie",
"Publica um texto no status: `POST /whatsapp/sendTextToStorie`."
)
action(
:send_image_to_storie,
"sendImageToStorie",
"Publica uma imagem no status: `POST /whatsapp/sendImageToStorie`."
)
action(
:send_video_to_storie,
"sendVideoToStorie",
"Publica um vídeo no status: `POST /whatsapp/sendVideoToStorie`."
)
action(
:check_number_status,
"checkNumberStatus",
"Verifica se um número tem WhatsApp: `POST /whatsapp/checkNumberStatus`."
)
action(
:get_all_chats,
"getAllChats",
"Lista as conversas do device: `POST /whatsapp/getAllChats`."
)
action(
:get_all_contacts,
"getAllContacts",
"Lista os contatos do device: `POST /whatsapp/getAllContacts`."
)
action(
:get_all_groups,
"getAllGroups",
"Lista os grupos do device: `POST /whatsapp/getAllGroups`."
)
action(
:get_profile_pic,
"getProfilePic",
"Foto de perfil de um número: `POST /whatsapp/getProfilePic`."
)
end