Put it on a channel

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; 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. 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, WhatsApp or Instagram.

  1. 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)

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

    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.

  2. 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)

    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.

    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.

  3. 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)

    const channelId = result.channels[0].id;
    
    await platic.channels.update(channelId, { defaultAgentId: agentId });

    To leave the channel without an agent, send "defaultAgentId": null. If the channel was already connected, find its id with List channels or by asking your assistant which channels you have.

  4. 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)

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

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

Check it worked

Check Get the channel: 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.

Next steps