Começar
Quickstart
Um caminho completo do primeiro request até a primeira resposta no WhatsApp.
1. Configure as variáveis
HOOKCLOUD_API_URL=https://api.hookcloud.app/functions/v1/swift-worker
HOOKCLOUD_PUBLISHABLE_KEY=SUA_PUBLISHABLE_KEY
HOOKCLOUD_PARTNER_API_KEY=hc_partner_live_SUA_CHAVE
PARTNER_WEBHOOK_URL=https://api.seusistema.com/webhooks/whatsapp
META_GRAPH_VERSION=v25.02. Crie ou atualize o cliente
curl --request POST 'https://api.hookcloud.app/functions/v1/swift-worker' \
--header 'apikey: SUA_PUBLISHABLE_KEY' \
--header 'Authorization: Bearer hc_partner_live_SUA_CHAVE' \
--header 'Content-Type: application/json' \
--data '{
"route": "upsert-partner-customer",
"external_customer_id": "cliente_56790",
"customer_name": "Clínica Mais Vida",
"customer_email": "contato@maisvida.com",
"customer_phone": "5511999999999"
}'3. Crie a instância e gere o Connect Flow
curl --request POST 'https://api.hookcloud.app/functions/v1/swift-worker' \
--header 'apikey: SUA_PUBLISHABLE_KEY' \
--header 'Authorization: Bearer hc_partner_live_SUA_CHAVE' \
--header 'Content-Type: application/json' \
--data '{
"route": "create-customer-instance",
"external_customer_id": "cliente_56790",
"instance_key": "cliente_56790-whatsapp-principal",
"instance_name": "Atendimento principal",
"create_connect_session": true,
"return_url": "https://app.seusistema.com/integracoes/whatsapp",
"cancel_url": "https://app.seusistema.com/integracoes/whatsapp",
"success_url": "https://partner-connect.hookcloud.app/connect/success",
"error_url": "https://partner-connect.hookcloud.app/connect/error"
}'{
"ok": true,
"instance_id": "UUID_DA_INSTANCIA",
"connect_session_id": "UUID_DA_SESSAO",
"connect_url": "https://partner-connect.hookcloud.app/connect?token=..."
}4. Abra o Connect Flow
Abra connect_url em popup ou nova aba. O cliente final conclui o Embedded Signup da Meta; a HookCloud salva WABA, Phone Number ID, nome verificado, qualidade, token criptografado e callback remoto.
const popup = window.open(connectUrl, 'hookcloudConnect', 'popup,width=860,height=760');
window.addEventListener('message', (event) => {
if (event.origin !== 'https://partner-connect.hookcloud.app') return;
if (event.data?.type === 'hookcloud_connect_close') popup?.close();
});Referência Meta: Embedded Signup oficial
5. Consulte o status
curl --request GET \
--url 'https://api.hookcloud.app/functions/v1/swift-worker?route=get-partner-instance&instance_id=UUID_DA_INSTANCIA' \
--header 'apikey: SUA_PUBLISHABLE_KEY' \
--header 'Authorization: Bearer hc_partner_live_SUA_CHAVE'6. Receba o webhook operacional
O endpoint do partner deve responder ao desafio GET da Meta e aceitar POSTs. O phone_number_id identifica qual instância recebeu a mensagem.
app.get('/webhooks/whatsapp', (req, res) => {
const mode = req.query['hub.mode'];
const token = req.query['hub.verify_token'];
const challenge = req.query['hub.challenge'];
if (mode === 'subscribe' && token === process.env.META_VERIFY_TOKEN) {
return res.status(200).send(challenge);
}
return res.sendStatus(403);
});
app.post('/webhooks/whatsapp', express.json(), async (req, res) => {
res.sendStatus(200); // responda rápido
const value = req.body?.entry?.[0]?.changes?.[0]?.value;
const phoneNumberId = value?.metadata?.phone_number_id;
const message = value?.messages?.[0];
// mapear phoneNumberId → cliente → automação
});Referência Meta: Webhooks oficiais
7. Responda pela Graph API
curl --request POST 'https://graph.facebook.com/v25.0/PHONE_NUMBER_ID/messages' \
--header 'Authorization: Bearer META_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"messaging_product": "whatsapp",
"to": "5511999999999",
"type": "text",
"text": { "body": "Olá! Como podemos ajudar?" }
}'Referência Meta: Mensagens da Cloud API
Checklist de conclusão
- Cliente salvo com ID externo estável
- Instância salva com UUID e instance_key
- Connect Flow concluído
status=connectedremote_callback_status=active- Webhook recebe mensagens
- Backend envia resposta pela Graph API
Esta página ajudou?Use o Partner Portal para suporte e compartilhe o link desta seção.
