---
docId: doc_e349097fb9b84425b22bbd286867f551
title: Use channels through the API
description: "Connect channels to your product, receive messages by webhook and send WhatsApp templates or email."
---

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

# Use channels through the API

Use Platica channels to communicate with your customers from your product. Receive messages by webhook and send WhatsApp templates or email from your backend. You can do this without an AI agent.

This example connects a WhatsApp number, receives its events and sends the `order_ready` template. Your application decides how to handle replies.

## Before you start

- Your Platica API key in `PLATIC_API_KEY`.
- Access to connect a WhatsApp number in the workspace.
- For the SDK, Node.js 20.3 or newer and [`platic-sdk`](/sdk/install).
- A webhook receiver with an HTTPS URL and a signing secret.
- An [approved template](/guides/whatsapp-templates): here, `order_ready` in `es_MX`, with variables for name and order.

<Steps>
<Steps.Step>

**Connect the channel**

[Request the connection](/api-reference/channels/connections/create) without `agentId`:

<Ways tabs="api,sdk">
<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": "whatsapp" }'
```

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

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

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

const connection = await platic.channels.connect({ type: "whatsapp" });
console.log(connection.authorizeIn);
```

</Ways.Way>
</Ways>

Save the response's `id` in `CONNECTION_ID`. Open `authorizeIn` with an account that has access to Integrations and complete the WhatsApp wizard. The connection expires after 24 hours by default.

[Check the connection](/api-reference/channels/connections/get) until `status` is `connected`. Save the `prefixedChannelId` from `channels` in `CHANNEL_ID`. To leave the channel without an agent, [set `defaultAgentId: null`](/api-reference/channels/update):

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

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

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

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

```ts
const connected = await platic.channels.connections.wait(connection.id);
if (connected.status !== "connected") throw new Error(connected.status);

const channelId = connected.channels[0]!.prefixedChannelId!;
await platic.channels.update(channelId, { defaultAgentId: null });
```

</Ways.Way>
</Ways>

If the channel is already connected, find its `prefixedChannelId` with [List channels](/api-reference/channels/list) and remove its assigned agent if needed.

</Steps.Step>
<Steps.Step>

**Receive messages in your system**

[Create a webhook](/api-reference/webhooks/create) for `message.created` and `message.updated`. Use your receiver's URL and secret:

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

```bash
curl https://api.platic.ai/v1/webhooks \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My product",
    "url": "'$WEBHOOK_URL'",
    "events": ["message.created", "message.updated"],
    "secret": "'$PLATIC_WEBHOOK_SECRET'"
  }'
```

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

```ts
const webhook = await platic.webhooks.create({
  name: "My product",
  url: process.env.WEBHOOK_URL!,
  events: ["message.created", "message.updated"],
  secret: process.env.PLATIC_WEBHOOK_SECRET!,
});
console.log(webhook.id, webhook.status);
```

</Ways.Way>
</Ways>

Check that the webhook is `enabled`. If it stays in `draft`, check the receiver and [test it](/api-reference/webhooks/test). The test checks the URL; events arrive when messages occur.

Verify the signature, skip repeated events by `id` and respond with `2xx` promptly. Follow [Receive webhooks](/guides/webhooks) for setup and [Delivery and signatures](/api-reference/webhooks/signatures) to validate the body.

For `message.created`, read these [fields](/api-reference/webhooks/payloads#messages):

| Field | Purpose |
|---|---|
| `id` | Identify the event and skip duplicates |
| `data.message.direction` | Distinguish `incoming` and `outgoing` messages |
| `data.message.content` | Read the message text |
| `data.conversation.id` | Read the conversation history |
| `data.client.phoneNumber` | Identify the WhatsApp contact's phone number |

To handle incoming messages, process only `direction: "incoming"`. This prevents messages sent by your own system from triggering another reply.

</Steps.Step>
<Steps.Step>

**Send a template from your backend**

[Send the approved template](/api-reference/messages/send-template) from `CHANNEL_ID`. `conversationId` takes the recipient's international phone number without `+`. `responderAgentId: null` leaves the conversation without an agent.

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

```bash
curl https://api.platic.ai/v1/messages/template \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelId": "'$CHANNEL_ID'",
    "conversationId": "5215512345678",
    "responderAgentId": null,
    "template": {
      "name": "order_ready",
      "language": "es_MX",
      "params": ["Ana", "A-1024"]
    }
  }'
```

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

```ts
const sent = await platic.messages.sendTemplate({
  channelId,
  conversationId: "5215512345678",
  responderAgentId: null,
  template: {
    name: "order_ready",
    language: "es_MX",
    params: ["Ana", "A-1024"],
  },
});
console.log(sent.messageId, sent.status);
```

</Ways.Way>
</Ways>

The `params` values must match the template's variables. The sending number and template must belong to the same WhatsApp Business account. Check [the Meta charges that apply to your template](/api-reference/whatsapp-templates/analytics).

To send email without an agent, connect Gmail, Outlook or a mailbox on your domain and use [`POST /v1/messages/email`](/api-reference/messages/send-email). [Sending free-form text through WhatsApp, Instagram or Messenger](/api-reference/messages/send) requires an active agent associated with the channel and an open service window.

</Steps.Step>
</Steps>

## Check it worked

Send a message to the connected number from your phone. Find `message.created` with `direction: "incoming"` on your receiver. Then send the template to your own number and check `messageId`, status and delivery events.

Conversations also appear in the Platica inbox. To add automatic replies later, [assign an agent to the channel](/guides/connect-a-channel).

## Next steps

- [Email through the API](/api-reference/channels/email): start threads and reply to emails.
- [Conversations](/api-reference/conversations): search, read the history, assign, tag and archive threads.
- [Chat API](/guides/chat-api): integrate an agent with your own interface.
