---
docId: doc_f2a36faba8bc48aba8b6288dc9222958
title: Integrate a chat into your product
sidebarTitle: Integrate a chat into your product
description: "Show your agent's chat inside a screen in your product."
---

<script>
  import { Steps, Ways, Collapsible } from '$lib/components';
</script>

# Integrate a chat into your product

<span id="add-a-chat-to-your-site"></span>

<span id="what-youll-build"></span>

Show your agent's chat inside a screen in your product, such as an order page.

## Before you start

You need a [published agent](/guides/create-an-agent) with its id in `AGENT_ID`, and access to your site's HTML.

To use the platform, see [Web chat and Web page](/help/integrations/web-chat).

<Steps>
<Steps.Step>

**Create the web chat**

Set the name, agent and your site's domain. The web chat is created published and needs no additional authorization. ([Create a web chat](/api-reference/web-chats/create))

<Ways tabs="api,sdk,asistente">
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/webchats \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Acme", "agentId": "'$AGENT_ID'", "allowedDomains": ["acme.com"] }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
import { Platic } from "platic-sdk";

const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
const agentId = process.env.AGENT_ID!;

const webchat = await platic.webchats.create({
  name: "Acme",
  agentId,
  allowedDomains: ["acme.com"],
});
console.log(webchat.embed.inline);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Create a web chat for acme.com that the Sales agent answers.

</Ways.Say>

Tool: [`create_webchat`](/mcp/tools#create_webchat) and answers with the code to paste.

</Ways.Way>
</Ways>

The response has the web chat's `id`: keep it in `WEBCHAT_ID`. When you create it, the name is also the one the visitor sees in the chat; later you change it in `config.content.assistantName`.

</Steps.Step>
<Steps.Step>

**Mount the chat inside your screen**

Use `embed.inline` to show the open chat inside a container. The step 1 response includes that code and `embed.publicKey`, the public key you can put in your HTML. ([Get a web chat](/api-reference/web-chats/get))

<Ways tabs="api,sdk,asistente">
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/webchats/$WEBCHAT_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
const { embed } = await platic.webchats.get(webchat.id);
console.log(embed.inline);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Give me embed.inline for Acme's web chat to show inside an order page.

</Ways.Say>

Tool: [`get_webchat`](/mcp/tools#get_webchat).

</Ways.Way>
</Ways>

Place the container in the screen where you need the chat. Use your `embed.publicKey` in `data-webchat` and the container's selector in `data-target`.

```html
<section class="order-page">
  <h1>Order A-1024</h1>
  <p>Ask our assistant about your order.</p>
  <div id="order-chat"></div>
</section>

<script
  src="https://chat.platica.mx/widget.js"
  data-webchat="wc_pub_7Hq2LmN4pR8sT1vX"
  data-target="#order-chat"
  defer>
</script>
```

The chat loads inside `#order-chat` when this screen opens. Set its height with `config.inline.height` and `config.inline.minHeight`.

The container defines where the chat appears. To send identity and context from your backend with your own interface, use the [Chat API](/guides/chat-api).

<Collapsible summary="You can also use a floating button">

To show the chat button, paste `embed.script` before `</body>`:

```html
<script
  src="https://chat.platica.mx/widget.js"
  data-webchat="wc_pub_7Hq2LmN4pR8sT1vX"
  defer>
</script>
```

The button opens the chat when the visitor clicks it.

</Collapsible>

Open the order screen and send a message from the embedded chat.

To test from your computer, add the local domain to `allowedDomains`, such as `localhost:5173`. To mount it when a React or Svelte component opens and remove it when you leave, see [Embed it in your site](/api-reference/web-chats/embed).

</Steps.Step>
<Steps.Step>

**Change how it looks and publish**

Change the main color and the greeting. Configuration changes are saved without publishing: your site stays the same until you publish. ([Update a web chat](/api-reference/web-chats/update), [Publish a web chat](/api-reference/web-chats/publish))

<Ways tabs="api,sdk,asistente">
<Ways.Way name="api">

```bash
curl -X PATCH https://api.platic.ai/v1/webchats/$WEBCHAT_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "config": { "appearance": { "primary": "#E4572E" }, "content": { "welcomeTitle": "Hi! Looking for something in particular?" } } }'

curl -X POST https://api.platic.ai/v1/webchats/$WEBCHAT_ID/publish \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.webchats.update(webchat.id, {
  config: {
    appearance: { primary: "#E4572E" },
    content: { welcomeTitle: "Hi! Looking for something in particular?" },
  },
});

await platic.webchats.publish(webchat.id);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Make Acme's chat color #E4572E and greet with "Hi! Looking for something in particular?". Then publish it.

</Ways.Say>

Tool: [`update_webchat`](/mcp/tools#update_webchat) and then [`publish_webchat`](/mcp/tools#publish_webchat).

</Ways.Way>
</Ways>

You only send what changes: the rest of the configuration stays the same. Before publishing, `hasUnpublishedChanges` is `true`; after, `false`. The code you pasted doesn't change. What you can change is in [the configuration](/api-reference/web-chats).

</Steps.Step>
</Steps>

## Check it worked

Use [Get the web chat](/api-reference/web-chats/get) to check that `hasUnpublishedChanges` is `false`. Open your product screen and check that the chat appears inside the container with the published color and greeting. Send a message and find the conversation in Platica's inbox, where your team can read or take it over.

The agent, the name and the domains change with the same `PATCH` and apply right away, without publishing. To turn the chat off, disconnect the channel; to turn it on, publish it again. See [Web chat](/api-reference/web-chats).

## Next steps

- [Embed it in your site](/api-reference/web-chats/embed): inside a container, from your code or in React and Svelte.
- [Put it on a channel](/guides/connect-a-channel) so it also answers WhatsApp, Messenger or Instagram.
- [Conversations](/api-reference/conversations): read, search and count what the agent is handling, or pause it to answer yourself.
- [Versions and how to go back](/guides/versions), in case an agent publication doesn't work.
