Crear un web chat
SDK platic.webchats.create()
Crea y publica un web chat. La respuesta incluye embed.script para tu HTML. Con mode en page o both, también incluye el enlace a su página en embed.pageUrl.
Ejemplo
curl https://api.platic.ai/v1/webchats \
-H "Authorization: Bearer $PLATIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Support", "agentId": "'"$AGENT_ID"'", "allowedDomains": ["example.com"] }' await platic.webchats.create({ name: "Support", agentId: "agent_123", allowedDomains: ["example.com"] }); Parámetros de consulta
| Parámetro | Tipo | Descripción | Requerido |
|---|---|---|---|
workspace | string | Solo si tu credencial tiene varios workspaces: en cuál crearlo | — |
Cuerpo de la solicitud
{
"name": "Tienda Ejemplo",
"agentId": "tVKljCHCNiebQdasHeit",
"allowedDomains": ["tiendaejemplo.mx"]
} Parámetros del cuerpo
| Parámetro | Tipo | Descripción | Requerido |
|---|---|---|---|
name | string | De 1 a 200 caracteres. También es el nombre del asistente que ve el visitante, hasta que cambies config.content.assistantName | ✓ |
agentId | string | null | El agente que atiende sus conversaciones. Si lo omites, queda sin agente | — |
mode | string | embed (en tu sitio), page (en una página de Platica) o both. Por omisión, both | — |
allowedDomains | string[] | Los dominios donde puede abrir el chat, hasta 50. Platica los guarda en minúsculas, sin protocolo, sin ruta y sin repetir. Acepta *.tiendaejemplo.mx y localhost:5173. Sin dominios, no abre en ningún sitio | — |
config | object | Solo lo que quieras distinto de los valores por omisión. Ver la configuración | — |
Si mandas dominios y no mandas config.behavior.displayRules, el chat aparece en todas las páginas de esos dominios.
Respuesta
201 Created. data es el web chat, ya publicado.
{
"status": "success",
"message": "Web chat created and published",
"data": {
"id": "wc-7Hq2LmN4pR8sT1vX",
"name": "Tienda Ejemplo",
"agentId": "tVKljCHCNiebQdasHeit",
"mode": "both",
"allowedDomains": ["tiendaejemplo.mx"],
"config": {
"enabled": true,
"content": {
"assistantName": "Tienda Ejemplo",
"welcomeTitle": "¿En qué podemos ayudarte?",
"welcomeMessage": "Inicia una conversación con nuestro equipo.",
"placeholder": "Escribe un mensaje…",
"onlineLabel": "En línea",
"offlineLabel": "Fuera de horario",
"offlineMessage": "Estamos fuera de horario. Déjanos un mensaje y te responderemos pronto.",
"prechatTitle": "Antes de comenzar",
"startButtonLabel": "Iniciar conversación"
},
"behavior": {
"rememberOpen": false,
"displayRules": [{ "domain": "tiendaejemplo.mx", "includePaths": ["/**"], "excludePaths": [] }]
}
},
"published": true,
"hasUnpublishedChanges": false,
"embed": {
"publicKey": "wc_pub_7Hq2LmN4pR8sT1vX",
"script": "<script\n src=\"https://chat.platica.mx/widget.js\"\n data-webchat=\"wc_pub_7Hq2LmN4pR8sT1vX\"\n defer>\n</script>",
"inline": "<div id=\"platica-chat\"></div>\n\n<script\n src=\"https://chat.platica.mx/widget.js\"\n data-webchat=\"wc_pub_7Hq2LmN4pR8sT1vX\"\n data-target=\"#platica-chat\"\n defer>\n</script>",
"pageUrl": "https://chat.platica.mx/chat?webchat=wc_pub_7Hq2LmN4pR8sT1vX"
},
"health": { "state": "ok", "reason": null, "since": "2026-11-12T18:30:00.000Z" },
"creationDate": "2026-11-12T18:30:00.000Z",
"lastUpdate": "2026-11-12T18:30:00.000Z",
"nextStep": "Created and published. Paste embed.script in the site's HTML, before </body>; embed.inline puts the chat inside a container of the page instead. Share embed.pageUrl, or open it to try the chat."
}
} Guarda el id para editar y publicar el web chat. El ejemplo de config es parcial; la respuesta trae sus doce secciones. Consulta los campos en obtener un web chat.
Son los valores por omisión. Solo dependen de tu petición content.assistantName (el name) y behavior.displayRules (una regla por dominio).
{
"enabled": true,
"interactiveResponses": { "enabled": false, "tokens": { "carousel": { "enabled": true } } },
"attachments": {
"enabled": true,
"maxFiles": 16,
"maxFileBytes": 5242880,
"maxMessageBytes": 15728640,
"acceptedTypes": ["image/jpeg", "image/png", "image/webp"],
"documents": {
"enabled": false,
"maxFileBytes": 10485760,
"acceptedTypes": [
"application/pdf",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"text/markdown",
"text/plain",
"text/csv"
]
},
"audio": {
"enabled": false,
"maxFileBytes": 10485760,
"acceptedTypes": ["audio/mpeg", "audio/mp4", "audio/ogg", "audio/wav", "audio/webm"]
},
"voiceNotes": { "enabled": false, "maxDurationSeconds": 180 }
},
"launcher": {
"position": "bottom-right",
"shape": "rounded",
"size": 56,
"radius": 14,
"offsetX": 20,
"offsetY": 20,
"backgroundColor": "#333533",
"iconColor": "#ffffff",
"iconAlt": "Abrir chat",
"ariaLabel": "Abrir chat",
"shadow": true,
"pulse": false,
"badge": { "enabled": false, "count": 1, "backgroundColor": "#ef4444", "textColor": "#ffffff" }
},
"window": {
"path": "/help/chat",
"width": 390,
"height": 720,
"gap": 12,
"mobileBreakpoint": 560,
"zIndex": 2147483000,
"allowFullscreen": true
},
"inline": { "height": 680, "minHeight": 480, "border": true, "shadow": false },
"appearance": {
"mode": "light",
"primary": "#00C577",
"radius": 16,
"font": "system",
"colors": {
"canvas": "#f7f8f5",
"surface": "#ffffff",
"surfaceMuted": "#f4f5f1",
"text": "#343434",
"textMuted": "#666666",
"border": "#111111",
"headerBackground": "#ffffff",
"headerText": "#343434",
"headerIcons": "#666666",
"visitorBackground": "#eef0e9",
"visitorText": "#343434",
"composerBackground": "#ffffff",
"composerInput": "#ffffff",
"sendBackground": "#00C577",
"sendIcon": "#111111",
"error": "#ef4444",
"online": "#00C577"
},
"visualEffects": { "enabled": true, "intensity": 60, "blur": 80, "motion": true }
},
"content": {
"assistantName": "Tienda Ejemplo",
"welcomeTitle": "¿En qué podemos ayudarte?",
"welcomeMessage": "Inicia una conversación con nuestro equipo.",
"placeholder": "Escribe un mensaje…",
"onlineLabel": "En línea",
"offlineLabel": "Fuera de horario",
"offlineMessage": "Estamos fuera de horario. Déjanos un mensaje y te responderemos pronto.",
"prechatTitle": "Antes de comenzar",
"startButtonLabel": "Iniciar conversación"
},
"suggestedMessages": {
"enabled": false,
"title": "¿Cómo podemos ayudarte?",
"subtitle": "Elige una opción para comenzar.",
"startConversationLabel": "Iniciar una conversación",
"logoAlt": "Logo de la empresa",
"cards": []
},
"prechat": {
"enabled": false,
"pageTitle": "Antes de comenzar",
"pageSubtitle": "Comparte tus datos para ofrecerte una mejor atención.",
"requestName": true,
"requestEmail": true,
"requestPhone": false,
"fields": [
{ "id": "name", "type": "text", "label": "Nombre", "placeholder": "Tu nombre", "required": true, "width": "full" },
{ "id": "email", "type": "email", "label": "Email", "placeholder": "tu@email.com", "required": true, "width": "full" }
]
},
"availability": { "status": "online" },
"behavior": {
"rememberOpen": false,
"displayRules": [{ "domain": "tiendaejemplo.mx", "includePaths": ["/**"], "excludePaths": [] }]
}
} Errores
| Status | details.code | Cuándo pasa |
|---|---|---|
400 | INVALID_REQUEST | Falta name, sobra un campo, un dominio o mode no es válido, o config tiene algo fuera de lo permitido. details.issues dice qué campo |
403 | FORBIDDEN | La credencial no tiene permiso de escritura en Integraciones, o el agente no está a su alcance |
404 | AGENT_NOT_FOUND | El agente de agentId no existe |
503 | WEBCHAT_SERVICE_UNAVAILABLE, WEBCHAT_SERVICE_TIMEOUT | El servicio del web chat no respondió |
Warning
Si recibes un 503, lista tus web chats antes de reintentar: el web chat pudo haberse creado.
Notas
- Pega
embed.scripten el HTML de tu sitio, antes de</body>. Las demás formas están en embeberlo en tu sitio. - El web chat también aparece en listar canales, con el mismo
id. - Necesita una API key del workspace, o un token OAuth con permiso de escritura en Integraciones y el alcance
platica:write.