← DocumentaciónReferencia

SDKs

Node.js y Python — instalación y ejemplos.

SDKs oficiales en Node.js y Python. Cubren toda la superficie del API REST con tipos completos + helper para verificar firmas de webhook. Dependencias mínimas — usamos fetch nativo en Node y httpx en Python.

Node.js — @replai/sdk

npm install @replai/sdk
# o pnpm / yarn / bun

Requiere Node 18+. Funciona en Bun, Deno y Cloudflare Workers (pasando tu propio fetch).

Uso básico

import { ReplaiClient } from '@replai/sdk';

const replai = new ReplaiClient({
  baseUrl: 'https://app.replai.tech/api',
  apiKey: process.env.REPLAI_API_KEY!,
});

// Sessions
const s = await replai.sessions.create({ name: 'Soporte' });
for await (const ev of replai.sessions.events(s.id)) {
  if (ev.type === 'qr') showQr(ev.qrDataUrl);
  if (ev.type === 'connected') break;
}

// Messages
await replai.messages.send({
  sessionId: s.id,
  to: '+5215512345678',
  text: 'Hola',
});

// Media (pre-upload flow)
const u = await replai.media.create({ mimeType: 'image/png', byteSize: bytes.length });
await fetch(u.signedUploadUrl, { method: 'PUT', body: bytes, headers: { 'content-type': 'image/png' } });
await replai.messages.send({
  sessionId: s.id,
  to: '+5215512345678',
  media: { type: 'image', mediaId: u.id, caption: 'logo' },
});

// Webhooks (verify)
import { verifyWebhookSignature } from '@replai/sdk';
const ok = verifyWebhookSignature({
  rawBody, signatureHeader, timestampHeader, secret,
});

Superficie

  • replai.sessions — create / list / get / metrics / events (SSE)
  • replai.messages.send — text + media
  • replai.conversations — list / messages / setBotEnabled
  • replai.media — create (signed PUT) / signedUrl
  • replai.knowledge — list / createText / createUrl / refresh / remove
  • replai.templates — CRUD + send
  • replai.optins — list / create / import / optOut
  • replai.webhooks — CRUD

Python — replai

pip install replai

Requiere Python 3.9+. Sync + async client comparten la misma surface.

Sync

from replai import Replai

with Replai(api_key="rk_live_...") as client:
    s = client.sessions.create(name="Soporte")
    for event in client.sessions.events(s["id"]):
        if event["type"] == "qr":
            print(event["qr"])
        elif event["type"] == "connected":
            break
    client.messages.send(
        session_id=s["id"],
        to="+5215512345678",
        text="Hola desde Python",
    )

Async

import asyncio
from replai import AsyncReplai

async def main():
    async with AsyncReplai(api_key="rk_live_...") as client:
        async for event in client.sessions.events("sess_abc"):
            print(event["type"])

asyncio.run(main())

Webhooks (verify)

from replai import verify_webhook_signature

@app.post("/replai/webhook")
async def webhook(request: Request):
    raw = await request.body()
    if not verify_webhook_signature(
        raw_body=raw,
        signature_header=request.headers.get("x-replai-signature", ""),
        timestamp_header=request.headers.get("x-replai-timestamp", ""),
        secret=os.environ["WEBHOOK_SECRET"],
    ):
        raise HTTPException(401)
    event = await request.json()
    ...

Otros lenguajes

El spec OpenAPI 3.1 está en /api/openapi.yaml — usa openapi-generator o tu herramienta favorita para generar clientes idiomáticos en Go, Ruby, PHP, Java, C#. Si terminas con un wrapper bueno que mantengas, avísanos y lo enlazamos aquí.

SDKs · Replai · WhatsApp con IA en Venezuela