Webhook - Quando ocorre um timeout na conversa
curl --request POST \
--url https://seudominio.com/webhooks/on-timeout \
--header 'Content-Type: application/json' \
--data '
{
"country_code": "+57",
"cellphone": "3161234567",
"session_id": "abcsderfwer3252432423-1324325235",
"conversation_id": 1234,
"question": {
"type": "open",
"text": "Olá mundo"
},
"timeout_at": "2021-10-07 08:53:22.572123",
"user_session_keys": [
{
"key": "age",
"value": "18",
"type": null
},
{
"key": "user_id",
"value": "12345",
"type": null
}
]
}
'import requests
url = "https://seudominio.com/webhooks/on-timeout"
payload = {
"country_code": "+57",
"cellphone": "3161234567",
"session_id": "abcsderfwer3252432423-1324325235",
"conversation_id": 1234,
"question": {
"type": "open",
"text": "Olá mundo"
},
"timeout_at": "2021-10-07 08:53:22.572123",
"user_session_keys": [
{
"key": "age",
"value": "18",
"type": None
},
{
"key": "user_id",
"value": "12345",
"type": None
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
country_code: '+57',
cellphone: '3161234567',
session_id: 'abcsderfwer3252432423-1324325235',
conversation_id: 1234,
question: {type: 'open', text: 'Olá mundo'},
timeout_at: '2021-10-07 08:53:22.572123',
user_session_keys: [
{key: 'age', value: '18', type: null},
{key: 'user_id', value: '12345', type: null}
]
})
};
fetch('https://seudominio.com/webhooks/on-timeout', 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://seudominio.com/webhooks/on-timeout",
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([
'country_code' => '+57',
'cellphone' => '3161234567',
'session_id' => 'abcsderfwer3252432423-1324325235',
'conversation_id' => 1234,
'question' => [
'type' => 'open',
'text' => 'Olá mundo'
],
'timeout_at' => '2021-10-07 08:53:22.572123',
'user_session_keys' => [
[
'key' => 'age',
'value' => '18',
'type' => null
],
[
'key' => 'user_id',
'value' => '12345',
'type' => null
]
]
]),
CURLOPT_HTTPHEADER => [
"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://seudominio.com/webhooks/on-timeout"
payload := strings.NewReader("{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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://seudominio.com/webhooks/on-timeout")
.header("Content-Type", "application/json")
.body("{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://seudominio.com/webhooks/on-timeout")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}"
response = http.request(request)
puts response.read_body{}Editor de Conversas
Corpo da Solicitação Webhook de Timeout (Fluxo Alternativo)
Este endpoint deve ser implementado no SEU servidor (por exemplo: https://seudominio.com/webhooks/on-timeout). O Treble chamará este webhook quando ocorrer um timeout na conversa (o usuário não responde dentro do tempo estabelecido). Você deve configurar a URL deste webhook no painel de administração do Treble.
POST
/
webhooks
/
on-timeout
Webhook - Quando ocorre um timeout na conversa
curl --request POST \
--url https://seudominio.com/webhooks/on-timeout \
--header 'Content-Type: application/json' \
--data '
{
"country_code": "+57",
"cellphone": "3161234567",
"session_id": "abcsderfwer3252432423-1324325235",
"conversation_id": 1234,
"question": {
"type": "open",
"text": "Olá mundo"
},
"timeout_at": "2021-10-07 08:53:22.572123",
"user_session_keys": [
{
"key": "age",
"value": "18",
"type": null
},
{
"key": "user_id",
"value": "12345",
"type": null
}
]
}
'import requests
url = "https://seudominio.com/webhooks/on-timeout"
payload = {
"country_code": "+57",
"cellphone": "3161234567",
"session_id": "abcsderfwer3252432423-1324325235",
"conversation_id": 1234,
"question": {
"type": "open",
"text": "Olá mundo"
},
"timeout_at": "2021-10-07 08:53:22.572123",
"user_session_keys": [
{
"key": "age",
"value": "18",
"type": None
},
{
"key": "user_id",
"value": "12345",
"type": None
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
country_code: '+57',
cellphone: '3161234567',
session_id: 'abcsderfwer3252432423-1324325235',
conversation_id: 1234,
question: {type: 'open', text: 'Olá mundo'},
timeout_at: '2021-10-07 08:53:22.572123',
user_session_keys: [
{key: 'age', value: '18', type: null},
{key: 'user_id', value: '12345', type: null}
]
})
};
fetch('https://seudominio.com/webhooks/on-timeout', 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://seudominio.com/webhooks/on-timeout",
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([
'country_code' => '+57',
'cellphone' => '3161234567',
'session_id' => 'abcsderfwer3252432423-1324325235',
'conversation_id' => 1234,
'question' => [
'type' => 'open',
'text' => 'Olá mundo'
],
'timeout_at' => '2021-10-07 08:53:22.572123',
'user_session_keys' => [
[
'key' => 'age',
'value' => '18',
'type' => null
],
[
'key' => 'user_id',
'value' => '12345',
'type' => null
]
]
]),
CURLOPT_HTTPHEADER => [
"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://seudominio.com/webhooks/on-timeout"
payload := strings.NewReader("{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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://seudominio.com/webhooks/on-timeout")
.header("Content-Type", "application/json")
.body("{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://seudominio.com/webhooks/on-timeout")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"country_code\": \"+57\",\n \"cellphone\": \"3161234567\",\n \"session_id\": \"abcsderfwer3252432423-1324325235\",\n \"conversation_id\": 1234,\n \"question\": {\n \"type\": \"open\",\n \"text\": \"Olá mundo\"\n },\n \"timeout_at\": \"2021-10-07 08:53:22.572123\",\n \"user_session_keys\": [\n {\n \"key\": \"age\",\n \"value\": \"18\",\n \"type\": null\n },\n {\n \"key\": \"user_id\",\n \"value\": \"12345\",\n \"type\": null\n }\n ]\n}"
response = http.request(request)
puts response.read_body{}Você também pode configurar o webhook de resposta para o caminho que sai de um nó no caso de timeout, também conhecido como fluxo alternativo.

Se você fizer isso, o corpo da solicitação HTTP que é enviado ao endpoint configurado no Treble adicionará o seguinte campo ao corpo da solicitação:
A resposta também pode ter novas variáveis para a sessão que podem ser atualizadas ou criadas para uso posterior na sessão. Ou seja, você pode adicioná-las na resposta do webhook como parte das

{
"timeout_at": "2021-10-07 08:53:22.572123"
}
user_session_keys.Corpo
application/json
Informações do evento de timeout
Evento que é disparado quando ocorre um timeout na conversa (o usuário não responde dentro do tempo estabelecido)
Resposta
200 - application/json
Resposta para atualizar ou adicionar informações à sessão
Objeto JSON com as novas informações que serão substituídas ou adicionadas à sessão para uso futuro. O serviço deve responder em menos de 10 segundos.
Esta página foi útil?