Configurar hook de agente
/v1/instances/{id}/agent-hookdesde M5token da instância ou adminQuando usar
Atualização parcial (cria se não existir). target: "builtin" usa o Atendente LiteZap embutido (sem URL); target: "url" (padrão) faz um POST assinado para url. Um secret ausente é gerado e aparece só nesta resposta. Campos desconhecidos são recusados.
Autenticação
Aceita o token da instância (só a própria instância) ou o token admin. Um token de outra instância recebe 403 forbidden (ou 404 not_found em webhooks de outra instância).
Parâmetros
Caminho
| Nome | Tipo | Descrição |
|---|---|---|
idobrigatório | string | Id da instância (inst_...). |
Corpo (JSON)
| Nome | Tipo | Descrição |
|---|---|---|
target | "url" | "builtin" | |
url | string | |
secret | string | |
enabled | boolean | |
timeout | string | |
context_messages | integer | (0–100) |
groups_enabled | boolean | |
human_pause | string | |
pause_on_api_send | boolean | |
ignore | string[] | |
max_replies_per_window | integer | |
reply_window | string |
Exemplo
curl -s -X PUT "$LITEZAP_URL/v1/instances/$ID/agent-hook" \ -H "Authorization: Bearer $LITEZAP_TOKEN" \ -d '{"target":"builtin","enabled":true}'const res = await fetch("http://localhost:8787/v1/instances/inst_7f3a9c2e5b1d4086/agent-hook", { method: "PUT", headers: { Authorization: `Bearer ${process.env.LITEZAP_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify({ "target": "builtin", "enabled": true }),});console.log(res.status, res.status === 204 ? "" : await res.json());import osimport requests
r = requests.put( "http://localhost:8787/v1/instances/inst_7f3a9c2e5b1d4086/agent-hook", headers={"Authorization": f"Bearer {os.environ['LITEZAP_TOKEN']}"}, json={ "target": "builtin", "enabled": True, }, timeout=150,)print(r.status_code, r.json() if r.content else "")package main
import ( "fmt" "io" "net/http" "os" "strings")
func main() { req, _ := http.NewRequest("PUT", "http://localhost:8787/v1/instances/inst_7f3a9c2e5b1d4086/agent-hook", strings.NewReader(`{"target":"builtin","enabled":true}`)) req.Header.Set("Authorization", "Bearer "+os.Getenv("LITEZAP_TOKEN")) req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, _ := io.ReadAll(resp.Body) fmt.Println(resp.Status, string(out))}<?phprequire 'vendor/autoload.php'; // composer require guzzlehttp/guzzle
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost:8787']);$res = $client->request('PUT', '/v1/instances/inst_7f3a9c2e5b1d4086/agent-hook', [ 'headers' => ['Authorization' => 'Bearer ' . getenv('LITEZAP_TOKEN')], 'json' => [ 'target' => 'builtin', 'enabled' => true, ], 'http_errors' => false,]);echo $res->getStatusCode(), ' ', $res->getBody(), PHP_EOL;Outros corpos de exemplo
{ "target": "url", "url": "https://meu-agente.exemplo.com/litezap", "enabled": true}Nos exemplos, LITEZAP_URL é a URL base (ex.: http://localhost:8787) e o token vem deLITEZAP_TOKEN (instância) ou LITEZAP_ADMIN_TOKEN.
Resposta
200 Configuração salva (secret só quando acabou de ser gerado).
Campos de AgentHook
configured | boolean | |
target | "url" | "builtin" | url: POST assinado para url; builtin: Atendente LiteZap embutido. |
url | string | |
enabled | boolean | |
timeout | string | |
context_messages | integer | |
groups_enabled | boolean | |
human_pause | string | |
pause_on_api_send | boolean | |
ignore | string[] | |
max_replies_per_window | integer | |
reply_window | string | |
secret_set | boolean | |
secret | string | Só quando acabou de ser gerado. |
Erros
| Código | HTTP | Retentável | O que fazer |
|---|---|---|---|
validation_failed | 400 | não | Corrija o corpo ou os parâmetros; a message diz o campo. |
unauthorized | 401 | não | Envie Authorization: Bearer <token> válido. |
forbidden | 403 | não | Use o token certo (admin, ou o da própria instância). |
instance_not_found | 404 | não | Confira o id da instância. |
Todo erro usa o envelope {"error":{"code","message","retryable"}}. Tabela completa em Erros.
Eventos gerados
Outras operações de Atendente IA: Ler hook de agente · Remover hook de agente · Ligar ou desligar o atendente numa conversa · Últimas chamadas do atendente · Ler o Atendente LiteZap · Configurar provedor do atendente · Modos prontos do atendente · Listar agentes · Criar agente · Ler agente · Alterar agente · Excluir agente · Ativar agente · Simular conversa · Uso e custo do atendente

