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.
  • A webhook receiver with an HTTPS URL and a signing secret.
  • An approved template: here, order_ready in es_MX, with variables for name and order.
  1. Connect the channel

    Request the connection without agentId:

    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);

    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 until status is connected. Save the prefixedChannelId from channels in CHANNEL_ID. To leave the channel without an agent, set defaultAgentId: null:

    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 });

    If the channel is already connected, find its prefixedChannelId with List channels and remove its assigned agent if needed.

  2. Receive messages in your system

    Create a webhook for message.created and message.updated. Use your receiver's URL and secret:

    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);

    Check that the webhook is enabled. If it stays in draft, check the receiver and test it. 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 for setup and Delivery and signatures to validate the body.

    For message.created, read these fields:

    FieldPurpose
    idIdentify the event and skip duplicates
    data.message.directionDistinguish incoming and outgoing messages
    data.message.contentRead the message text
    data.conversation.idRead the conversation history
    data.client.phoneNumberIdentify 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.

  3. Send a template from your backend

    Send the approved template from CHANNEL_ID. conversationId takes the recipient's international phone number without +. responderAgentId: null leaves the conversation without an agent.

    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);

    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.

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

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.

Next steps