Criar Sessão de Voz
curl --request POST \
--url https://api.zapsterapi.com/v1/voice/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"instance_ids": [
"ozj35qv418rpmlrb"
],
"scopes": [
"receive",
"dial"
],
"external_id": "atendente_42"
}
'import requests
url = "https://api.zapsterapi.com/v1/voice/sessions"
payload = {
"instance_ids": ["ozj35qv418rpmlrb"],
"scopes": ["receive", "dial"],
"external_id": "atendente_42"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instance_ids: ['ozj35qv418rpmlrb'],
scopes: ['receive', 'dial'],
external_id: 'atendente_42'
})
};
fetch('https://api.zapsterapi.com/v1/voice/sessions', 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.zapsterapi.com/v1/voice/sessions",
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([
'instance_ids' => [
'ozj35qv418rpmlrb'
],
'scopes' => [
'receive',
'dial'
],
'external_id' => 'atendente_42'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.zapsterapi.com/v1/voice/sessions"
payload := strings.NewReader("{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.zapsterapi.com/v1/voice/sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zapsterapi.com/v1/voice/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}"
response = http.request(request)
puts response.read_body{
"external_id": "atendente_42",
"url": "wss://voice.zapsterapi.com/session",
"token": "vg1.eyJ2IjoxLCJ0eXAiOiJzZXNzaW9uIn0.c2lnbmF0dXJl",
"expires_at": "2023-11-07T05:31:56Z"
}{
"errors": [
{
"code": "feature_not_available",
"message": "Voice calls are not available for this account."
}
]
}{
"errors": [
{
"code": "instance_not_found",
"message": "Instance not found."
}
]
}{
"errors": [
{
"code": "instance_update_required",
"message": "This instance is running an older version that does not support this feature. Power the instance off and on to update it, or contact support for help."
}
]
}Ligações
Criar Sessão de Voz
Gera o token com que o navegador de um atendente se registra para receber e fazer ligações das instâncias informadas.
POST
/
voice
/
sessions
Criar Sessão de Voz
curl --request POST \
--url https://api.zapsterapi.com/v1/voice/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"instance_ids": [
"ozj35qv418rpmlrb"
],
"scopes": [
"receive",
"dial"
],
"external_id": "atendente_42"
}
'import requests
url = "https://api.zapsterapi.com/v1/voice/sessions"
payload = {
"instance_ids": ["ozj35qv418rpmlrb"],
"scopes": ["receive", "dial"],
"external_id": "atendente_42"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instance_ids: ['ozj35qv418rpmlrb'],
scopes: ['receive', 'dial'],
external_id: 'atendente_42'
})
};
fetch('https://api.zapsterapi.com/v1/voice/sessions', 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.zapsterapi.com/v1/voice/sessions",
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([
'instance_ids' => [
'ozj35qv418rpmlrb'
],
'scopes' => [
'receive',
'dial'
],
'external_id' => 'atendente_42'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.zapsterapi.com/v1/voice/sessions"
payload := strings.NewReader("{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.zapsterapi.com/v1/voice/sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zapsterapi.com/v1/voice/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance_ids\": [\n \"ozj35qv418rpmlrb\"\n ],\n \"scopes\": [\n \"receive\",\n \"dial\"\n ],\n \"external_id\": \"atendente_42\"\n}"
response = http.request(request)
puts response.read_body{
"external_id": "atendente_42",
"url": "wss://voice.zapsterapi.com/session",
"token": "vg1.eyJ2IjoxLCJ0eXAiOiJzZXNzaW9uIn0.c2lnbmF0dXJl",
"expires_at": "2023-11-07T05:31:56Z"
}{
"errors": [
{
"code": "feature_not_available",
"message": "Voice calls are not available for this account."
}
]
}{
"errors": [
{
"code": "instance_not_found",
"message": "Instance not found."
}
]
}{
"errors": [
{
"code": "instance_update_required",
"message": "This instance is running an older version that does not support this feature. Power the instance off and on to update it, or contact support for help."
}
]
}Use este endpoint no seu back-end para gerar a sessão de voz de um atendente. Entregue
url e token ao navegador, que se registra com ZapsterVoice.register do SDK de voz e passa a receber as ligações das instâncias informadas e a poder ligar por elas.
Sua chave de API nunca vai para o navegador: o token da sessão vale 1 hora, só para as instâncias informadas, e o SDK pede um novo pouco antes de expirar (onTokenExpiring).
Todas as instâncias precisam pertencer à conta e estar com as ligações de voz ligadas. Se uma delas não atender a esses requisitos, a requisição inteira falha com 404 instance_not_found ou 403 feature_not_available.
Informe external_id com o identificador do atendente no seu sistema. Com ele, um atendente que recarrega a página retoma as ligações em andamento, e o identificador volta nos webhooks das ligações que ele atender ou fizer.Autorizações
Corpo
application/json
Resposta
Sessão criada