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_readyines_MX, with variables for name and order.
Connect the channel
Request the connection without
agentId:curl https://api.platic.ai/v1/channels/connections \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "type": "whatsapp" }'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
idinCONNECTION_ID. OpenauthorizeInwith an account that has access to Integrations and complete the WhatsApp wizard. The connection expires after 24 hours by default.Check the connection until
statusisconnected. Save theprefixedChannelIdfromchannelsinCHANNEL_ID. To leave the channel without an agent, setdefaultAgentId: null: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 }'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
prefixedChannelIdwith List channels and remove its assigned agent if needed.Receive messages in your system
Create a webhook for
message.createdandmessage.updated. Use your receiver's URL and secret: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'" }'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 indraft, check the receiver and test it. The test checks the URL; events arrive when messages occur.Verify the signature, skip repeated events by
idand respond with2xxpromptly. Follow Receive webhooks for setup and Delivery and signatures to validate the body.For
message.created, read these fields:Field Purpose idIdentify the event and skip duplicates data.message.directionDistinguish incomingandoutgoingmessagesdata.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.Send a template from your backend
Send the approved template from
CHANNEL_ID.conversationIdtakes the recipient's international phone number without+.responderAgentId: nullleaves the conversation without an agent.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"] } }'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
paramsvalues 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
- Email through the API: start threads and reply to emails.
- Conversations: search, read the history, assign, tag and archive threads.
- Chat API: integrate an agent with your own interface.