ORYKSAORYKSADevelopers
Obter chaves de API

Chat

Envia a mensagem de um cliente e recebe a resposta do colaborador de IA, com o conhecimento e as regras do negócio aplicados.

POST/v1/chat
curl https://api.oryksa.com/v1/chat \
  -H "Authorization: Bearer oryk_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hi! What are your opening hours?"}'
const res = await fetch("https://api.oryksa.com/v1/chat", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.ORYKSA_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ message: "Hi! What are your opening hours?" }),
});
const data = await res.json();
console.log(data.reply, data.conversation_id);
import os, requests

r = requests.post(
    "https://api.oryksa.com/v1/chat",
    headers={"Authorization": f"Bearer {os.environ['ORYKSA_API_KEY']}"},
    json={"message": "Hi! What are your opening hours?"},
    timeout=60,
)
data = r.json()
print(data["reply"], data["conversation_id"])
<?php
$ch = curl_init("https://api.oryksa.com/v1/chat");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("ORYKSA_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode(["message" => "Hi! What are your opening hours?"]),
]);
$data = json_decode(curl_exec($ch), true);
echo $data["reply"];
import 'dart:convert';
import 'package:http/http.dart' as http;

final res = await http.post(
  Uri.parse('https://api.oryksa.com/v1/chat'),
  headers: {
    'Authorization': 'Bearer $oryksaApiKey',
    'Content-Type': 'application/json',
  },
  body: jsonEncode({'message': 'Hi! What are your opening hours?'}),
);
final data = jsonDecode(res.body);
print(data['reply']);
val body = JSONObject(mapOf("message" to "Hi! What are your opening hours?")).toString()
val req = Request.Builder()
    .url("https://api.oryksa.com/v1/chat")
    .header("Authorization", "Bearer $oryksaApiKey")
    .post(body.toRequestBody("application/json".toMediaType()))
    .build()
OkHttpClient().newCall(req).execute().use { res ->
    val data = JSONObject(res.body!!.string())
    println(data.getString("reply"))
}
var req = URLRequest(url: URL(string: "https://api.oryksa.com/v1/chat")!)
req.httpMethod = "POST"
req.setValue("Bearer \(oryksaApiKey)", forHTTPHeaderField: "Authorization")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try JSONSerialization.data(withJSONObject: ["message": "Hi! What are your opening hours?"])
let (data, _) = try await URLSession.shared.data(for: req)
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
print(json["reply"] ?? "")

Parâmetros

CampoTipoDescrição
messagestringObrigatório. A mensagem do cliente, de 1 a 2000 caracteres.
conversation_idstringOpcional. O teu id para este cliente ou conversa (letras, dígitos, _ e -, máx. 64). Reutiliza-o para manter o contexto. Se não o enviares, é criado um novo e devolvido.
customer_namestringOpcional. Nome do cliente, usado pelo agente para personalizar as respostas.

Resposta

{
  "object": "chat_reply",
  "conversation_id": "a073e8dba25845fe9153840e8bc787c8",
  "status": "replied",
  "reply": "We are open Monday to Friday, 9am to 7pm. Would you like to book a visit?"
}
{
  "object": "chat_reply",
  "conversation_id": "a073e8dba25845fe9153840e8bc787c8",
  "status": "pending",
  "reply": null,
  "hint": "The reply is still being generated. Read it with GET /v1/conversations/a073e8dba25845fe9153840e8bc787c8"
}

Normalmente a resposta chega em 2 a 5 segundos e a API responde 200 com status: "replied". Se o agente precisar de mais de 40 segundos, a API responde 202 com status: "pending": lê a resposta mais tarde com GET /v1/conversations/{id} ou recebe-a pelo webhook message.replied.

Manter a conversa

curl https://api.oryksa.com/v1/chat \
  -H "Authorization: Bearer oryk_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "customer-4812",
    "customer_name": "Ana",
    "message": "Can I book for Saturday at 10am?"
  }'
await fetch("https://api.oryksa.com/v1/chat", {
  method: "POST",
  headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
  body: JSON.stringify({
    conversation_id: "customer-4812",   // your own id for this customer
    customer_name: "Ana",
    message: "Can I book for Saturday at 10am?",
  }),
});
requests.post(
    "https://api.oryksa.com/v1/chat",
    headers={"Authorization": f"Bearer {key}"},
    json={
        "conversation_id": "customer-4812",  # your own id for this customer
        "customer_name": "Ana",
        "message": "Can I book for Saturday at 10am?",
    },
)

O que o agente aplica

O mesmo motor do WhatsApp e do chat do site: perfil do negócio, conhecimento do Brain, produtos, regras do dono e regras de segurança, estilo das mensagens e limites do plano. Se o dono pausar a IA ou a desligar para os canais web, a API responde 503 agent_unavailable. As conversas criadas pela API aparecem no painel do dono como qualquer outro chat.