Este documento descreve a API de disparo de mensagens, suas propriedades, tipos suportados e exemplos de uso.
| Nome | Tipo | Obrigatório | Padrão |
|---|---|---|---|
| accountId | number | Sim | - |
| contact | Contact | Sim | - |
| message | Message | Sim | - |
| channelId | number | Sim | - |
| messageTimeout | number | Não | - |
| isPrivate | boolean | Não | false |
| tagId | number | Não | - |
| queueId | number | Não | - |
| session | Session | Não | - |
| status | string (automatic|pending|solved) | Não | automatic |
| ticketId | number | Não | - |
| userId | number | Não | - |
| summary | string | Não | - |
| from | string | Não | - |
| queued | boolean | Não | true |
| messageTimeoutBehavior | string (solve|flow) | Não | solve |
| messageTimeoutFlowId | number | Não | - |
| responseFlowId | number | Não | - |
| context | Context | Não |
type Contact = {
name: string;
phone: string;
};
Representa o contato que receberá a mensagem.
type Message =
| {
type: "text";
body: string;
}
| {
type: "contact";
name: string;
phone: string;
businessDescription: string;
}
| {
type: "template";
variables?: string[];
headerVariables?: string[];
buttonVariables?: string[];
name: string;
}
| {
type: "image";
url: string;
caption?: string;
}
| {
type: "pdf";
url: string;
fileName: string;
caption?: string;
}
| {
type: "document";
url: string;
filename: string;
caption: string;
};
Define o tipo de mensagem enviado e suas propriedades específicas.
type SendMessageFromApiSession = {
context: Record;
};
Permite passar variáveis de contexto que serão armazenadas na sessão do chatbot e acessíveis no fluxo a partir do objeto session. Exemplo: Na API envie session.context.nota_fiscal = 10020. No chatbot poderá acessar essa variável utilizando {{session.nota_fiscal}} que retornará o valor "10020".
type Context = {
header: string;
body: string;
buttons?: ButtonContext[];
};
type ButtonContext = {
type: 'link' | 'telephone' | 'copy';
title: string;
content: string;
};
Permite adicionar contexto no envio da mensagem
curl --request POST \
--url https://api.sacflow.io/api/send-message \
--header 'Authorization: Bearer API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"accountId": ACCOUNT_ID,
"channelId": CHANNEL_ID,
"contact": {
"name": "CONTACT_NAME",
"phone": "CONTACT_PHONE"
},
"message": {
"type": "template",
"name": "TEMPLATE_NAME"
},
"queued": false
}'
curl --request POST \
--url https://api.sacflow.io/api/send-message \
--header 'Authorization: Bearer API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"accountId": ACCOUNT_ID,
"channelId": CHANNEL_ID,
"contact": {
"name": "CONTACT_NAME",
"phone": "CONTACT_PHONE"
},
"message": {
"type": "template",
"name": "TEMPLATE_NAME",
"variables": ["VAR1", "VAR2"]
}
}'Para enviar um template com midia no header, existem 2 formas de fornecer o arquivo:
Opcao 1: Via URL publica (JSON)
curl --request POST \
--url https://api.sacflow.io/api/send-message \
--header 'Authorization: Bearer API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"accountId": ACCOUNT_ID,
"channelId": CHANNEL_ID,
"contact": {
"name": "CONTACT_NAME",
"phone": "CONTACT_PHONE"
},
"message": {
"type": "template",
"name": "TEMPLATE_NAME",
"variables": ["VAR1", "VAR2"],
"headerVariables": ["https://exemplo.com/arquivo.pdf"]
}
}'Opcao 2: Upload direto do arquivo (Multipart)
Envie o arquivo diretamente na requisicao usando multipart/form-data. O sistema faz o upload automaticamente e injeta a URL no template:
curl --request POST \
--url 'https://api.sacflow.io/api/send-message?accountId=ACCOUNT_ID' \
--header 'Authorization: Bearer API_TOKEN' \
-F 'payload={"accountId":ACCOUNT_ID,"channelId":CHANNEL_ID,"contact":{"name":"CONTACT_NAME","phone":"CONTACT_PHONE"},"message":{"type":"template","name":"TEMPLATE_NAME","variables":["VAR1","VAR2"]}}' \
-F 'headerMedia=@/caminho/para/arquivo.pdf'| Campo | Tipo | Descrição |
|---|---|---|
| payload | texto (JSON) | O body completo da requisicao, identico ao que seria enviado como JSON |
| headerMedia | arquivo | O arquivo de midia para o header do template (imagem, video ou documento) |
O accountId deve ser informado via query string (?accountId=ACCOUNT_ID) ou no header accountId, além de estar presente dentro do JSON do campo payload.
Para mais informações, entre em contato com o suporte da API via WhatsApp.