How to open a new conversation from a user to a teammate via API

If you want to create a new conversation and assign it to a specific teammate via API you can do it with this tutorial

Luca Micheli
Written by Luca MicheliLast update 1 year ago

If you want to open a conversation to notify your customer support or sales team about a new form submission, follow the steps below. This guide will show you how to use the Customerly API to create a function that opens a new conversation from a lead to an account.

Step 1: Create a Bridge File

First, you'll need to create a bridge file to communicate with the Customerly APIs. This file will serve as the connector between your system and the Customerly API.

Step 2: Access the API Endpoint

Depending on your environment, access the public API endpoint:

https://api.customerly.io/v1/messages

Step 3: Refer to the API Documentation

For detailed information on how to work with the API, check out the API documentation

Step 4: Example Implementation (PHP)

Here's a PHP example showing how to create a function to open a new conversation:

static function send_message($from_email, $account_id, $message)
{
    $ch = curl_init();
    $payload = array(
        "from" => array(
            "type" => "lead",
            "email" => $from_email
        ),
        "to" => array(
            "type" => "admin",
            "id" => $account_id,
        ),
        "content" => $message,
    );
    curl_setopt($ch, CURLOPT_URL, "https://api.customerly.io/v1/messages");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Authentication: AccessToken: " . CUSTOMERLY_API_KEY
    ));
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

Parameters:

- from_email: The lead's email address.

- account_id: The account ID, found in the teammates page in your project settings.

- message: The actual message to deliver to the account.

Note: Ensure you have your Customerly API Key from your Project settings.

Did this answer your question?