curl --request POST \
--url https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'x-api-key: <api-key>' \
--data '
{
"template": {
"id": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"parameters": {
"delivery_date": "3 de octubre",
"order_number": "A-10492"
},
"media": {
"type": "IMAGE",
"mediaId": "9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10",
"url": "https://cdn.example.com/promo/spring-sale.png"
}
}
}
'import requests
url = "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template"
payload = { "template": {
"id": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"parameters": {
"delivery_date": "3 de octubre",
"order_number": "A-10492"
},
"media": {
"type": "IMAGE",
"mediaId": "9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10",
"url": "https://cdn.example.com/promo/spring-sale.png"
}
} }
headers = {
"Idempotency-Key": "<idempotency-key>",
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
template: {
id: '4061e74e-f6fe-4072-a760-3aec0b64f7a6',
parameters: {delivery_date: '3 de octubre', order_number: 'A-10492'},
media: {
type: 'IMAGE',
mediaId: '9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10',
url: 'https://cdn.example.com/promo/spring-sale.png'
}
}
})
};
fetch('https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'template' => [
'id' => '4061e74e-f6fe-4072-a760-3aec0b64f7a6',
'parameters' => [
'delivery_date' => '3 de octubre',
'order_number' => 'A-10492'
],
'media' => [
'type' => 'IMAGE',
'mediaId' => '9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10',
'url' => 'https://cdn.example.com/promo/spring-sale.png'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template"
payload := strings.NewReader("{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template")
.header("Idempotency-Key", "<idempotency-key>")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"conversationId": "7d4a1f2e-3b5c-4d6e-8f9a-0b1c2d3e4f5a",
"messageId": "b6cf1c4a-2b1e-4e63-8f3e-0f9d1a2a1234",
"templateId": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"templateName": "order_shipped_promo"
}Enviar modelo
Envia um template de provedor do WhatsApp para uma conversa existente, como uma única mensagem lida por todos os contatos de WhatsApp da conversa. O remetente é a API key, que o Bridge mostra com o nome de remetente dela. Para iniciar uma conversa com um template, use POST /bridge/api/v1/workspaces/{workspaceId}/conversations com onboardingTemplates.
A conversa deve estar ativa, não atendida por um Agente e ter um contato de WhatsApp. Envie o template por template.id, aprovado para a linha e o idioma de cada contato de WhatsApp, com template.parameters indexados como GET /bridge/api/v1/workspaces/{workspaceId}/templates/{templateId} os retorna.
Um template de marketing ou de utilidade é recusado enquanto um contato da conversa estiver dentro do período de espera promocional do workspace: 409 BRIDGE_CONVERSATION_0406, com a espera em segundos em Retry-After. Ele também abre uma conversa que ainda não tem template inicial. O cabeçalho Idempotency-Key é obrigatório e mantido por 24 horas: a mesma chave com o mesmo envio responde 201 com Idempotent-Replayed: true e não envia nada de novo. Um 201 significa que o Bridge gravou a mensagem para envio; veja Respostas, erros e novas tentativas.
Todos os códigos de erro 4xx aparecem nas respostas. O que fazer com cada um: Envie um template para uma conversa existente.
curl --request POST \
--url https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'x-api-key: <api-key>' \
--data '
{
"template": {
"id": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"parameters": {
"delivery_date": "3 de octubre",
"order_number": "A-10492"
},
"media": {
"type": "IMAGE",
"mediaId": "9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10",
"url": "https://cdn.example.com/promo/spring-sale.png"
}
}
}
'import requests
url = "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template"
payload = { "template": {
"id": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"parameters": {
"delivery_date": "3 de octubre",
"order_number": "A-10492"
},
"media": {
"type": "IMAGE",
"mediaId": "9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10",
"url": "https://cdn.example.com/promo/spring-sale.png"
}
} }
headers = {
"Idempotency-Key": "<idempotency-key>",
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
template: {
id: '4061e74e-f6fe-4072-a760-3aec0b64f7a6',
parameters: {delivery_date: '3 de octubre', order_number: 'A-10492'},
media: {
type: 'IMAGE',
mediaId: '9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10',
url: 'https://cdn.example.com/promo/spring-sale.png'
}
}
})
};
fetch('https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'template' => [
'id' => '4061e74e-f6fe-4072-a760-3aec0b64f7a6',
'parameters' => [
'delivery_date' => '3 de octubre',
'order_number' => 'A-10492'
],
'media' => [
'type' => 'IMAGE',
'mediaId' => '9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10',
'url' => 'https://cdn.example.com/promo/spring-sale.png'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template"
payload := strings.NewReader("{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template")
.header("Idempotency-Key", "<idempotency-key>")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-connect-us.bridge.new/bridge/api/v1/workspaces/{workspaceId}/conversations/{conversationId}/send-template")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"template\": {\n \"id\": \"4061e74e-f6fe-4072-a760-3aec0b64f7a6\",\n \"parameters\": {\n \"delivery_date\": \"3 de octubre\",\n \"order_number\": \"A-10492\"\n },\n \"media\": {\n \"type\": \"IMAGE\",\n \"mediaId\": \"9b2f6a52-1f3c-4a53-8f58-3c6a2e7d1b10\",\n \"url\": \"https://cdn.example.com/promo/spring-sale.png\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"conversationId": "7d4a1f2e-3b5c-4d6e-8f9a-0b1c2d3e4f5a",
"messageId": "b6cf1c4a-2b1e-4e63-8f3e-0f9d1a2a1234",
"templateId": "4061e74e-f6fe-4072-a760-3aec0b64f7a6",
"templateName": "order_shipped_promo"
}Autorizações
Cabeçalhos
Obrigatório. Uma chave que você escolhe para cada envio, de 1 a 255 caracteres, como o id de operação do seu sistema. Envie a mesma chave para repetir esse envio: por 24 horas o Bridge responde com a mensagem que a primeira requisição gravou, em vez de enviar de novo.
1 - 255"erp-order-981-shipped"
Parâmetros de caminho
Corpo
Resposta
O Bridge gravou a mensagem para envio, ou uma requisição anterior com a mesma Idempotency-Key o fez. Veja Respostas e novas tentativas.
A mensagem que o Bridge gravou para enviar o template à conversa.
Esta página foi útil?

