---
docId: doc_6c577fdb42b94c81b4167504308414b2
title: Put it on a channel
description: "Connect a channel and assign the agent that will handle its messages."
---

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

# Put it on a channel

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

Connect a channel to receive and send messages in Platica.

- **With an agent:** assign it to the channel to handle conversations.
- **From your product:** use channels and webhooks as communication infrastructure. Follow [Use channels through the API](/guides/messaging-api); connecting a channel requires no agent.

In both cases, someone must authorize the connection with the provider.

## Before you start

To follow the automatic-reply example, you need:

- A [published agent](/guides/create-an-agent). Save its id in `AGENT_ID`.
- Someone who manages the Facebook Page and has access to **Integrations** in Platica.

If the channel is already connected, start at step 3.

To connect it from the platform, see [Messenger](/help/integrations/messenger), [WhatsApp](/help/integrations/whatsapp/connect-number) or [Instagram](/help/integrations/instagram).

<Steps>
<Steps.Step>

**Ask for the connection**

Request an authorization link. If you include `agentId`, that agent is assigned to the channel when you complete the connection. ([Connect a channel](/api-reference/channels/connections/create))

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

```bash
curl https://api.platic.ai/v1/channels/connections \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "messenger", "agentId": "'$AGENT_ID'" }'
```

</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 connection = await platic.channels.connect({ type: "messenger", agentId });
console.log(connection.authorizeIn);
```

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

Connect Acme's Facebook Page through Messenger and have the Sales agent answer it.

</Ways.Say>

Tool: [`connect_channel`](/mcp/tools#connect_channel) and answers with a link.

</Ways.Way>
</Ways>

Save the connection's `id` in `CONNECTION_ID`. Open `authorizeIn` to authorize in Platica, or share `shareUrl` with the Page's administrator, even if they don't have a Platica account.

The connection and its links expire in 24 hours. Change the lifetime with `expiresInMinutes`, from 15 minutes to 7 days.

<Note>

**WhatsApp** works the same way with `"type": "whatsapp"`, but it is finished in Platica: `authorizeIn` opens the WhatsApp setup wizard, and someone on your team with access to **Integrations** completes it there. There is no `shareUrl`. The connection becomes `connected` when the WhatsApp channel is created. See [Connect a channel](/api-reference/channels/connections/create).

</Note>

</Steps.Step>
<Steps.Step>

**Authorize in Platica**

Open the link or share it with the Page's administrator. The screen asks you to sign in to Platica and shows the destination workspace and who requested the connection. Then sign in with Facebook, choose the Page and check the connection's status. ([Get a connection](/api-reference/channels/connections/get))

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

```bash
curl https://api.platic.ai/v1/channels/connections/$CONNECTION_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

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

```ts
const result = await platic.channels.connections.wait(connection.id);
console.log(result.status, result.channels);
```

`wait` checks the connection every 5 seconds and returns when it finishes or when it asks you to choose.

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

I authorized the Page. Is it done?

</Ways.Say>

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

</Ways.Way>
</Ways>

When `status` says `connected`, `channels` has the channel with its `id`: keep it in `CHANNEL_ID`. If it says `awaiting_selection`, the account has several Pages: choose on the same Platica page or with [Choose what to connect](/api-reference/channels/connections/select-assets).

</Steps.Step>
<Steps.Step>

**Choose which agent answers it**

Assign the agent if you didn't include `agentId` in step 1, or choose a different agent. The agent uses its published version; draft changes reach the channel when you publish them. ([Update a channel](/api-reference/channels/update))

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

```bash
curl -X PATCH https://api.platic.ai/v1/channels/$CHANNEL_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "defaultAgentId": "'$AGENT_ID'" }'
```

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

```ts
const channelId = result.channels[0].id;

await platic.channels.update(channelId, { defaultAgentId: agentId });
```

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

Put the Sales agent in charge of Acme's Messenger.

</Ways.Say>

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

</Ways.Way>
</Ways>

To leave the channel without an agent, send `"defaultAgentId": null`. If the channel was already connected, find its `id` with [List channels](/api-reference/channels/list) or by asking your assistant which channels you have.

</Steps.Step>
<Steps.Step>

**Turn it off when needed**

Set the agent's `status` to `inactive` to stop it from handling messages across its assigned channels. Its configuration and channels stay assigned. ([Update an agent](/api-reference/agents/update))

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

```bash
curl -X PATCH https://api.platic.ai/v1/agents/$AGENT_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "status": "inactive" }'
```

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

```ts
await platic.agents.update(agentId, { status: "inactive" });
```

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

Turn off the Sales agent.

</Ways.Say>

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

</Ways.Way>
</Ways>

To turn it back on, use `active`. It applies right away and doesn't create a version.

</Steps.Step>
</Steps>

## Check it worked

Check [Get the channel](/api-reference/channels/get): `defaultAgentId` should match your agent and `health` indicate that the channel is available. Send a message to the Page and check that the agent replies.

If the channel stops working, check `health` to find out what it needs. If authorization was lost, request another connection of the same type. See [Channels](/api-reference/channels).

## Next steps

- [Add a chat to your site](/guides/web-chat) so it also answers whoever opens your page.
- [Send WhatsApp templates](/guides/whatsapp-templates) to start conversations on WhatsApp.
- [Email by API](/api-reference/channels/email): with a mailbox connected in Platica, write and reply to emails from your code.
- [Conversations](/api-reference/conversations): read, search and count what the agent is handling, or pause it to answer yourself.
- [Receive webhooks](/guides/webhooks): learn in your server about every conversation and message.
- [Usage](/api-reference/usage): measure consumption and autonomy.
- [Versions and how to go back](/guides/versions), in case a publication doesn't work.
