Rate this page:

Custom channels. Connecting the Chat2Desk channel

To connect the Chat2Desk channel, register a Voximplant Kit account or use an existing one. In this account, you need to create a custom channel and get an API token in the Integrations section. Also, you must have a Chat2Desk account in which you need to generate an API token to work with the Chat2Desk API.

To integrate with Chat2Desk, you need to have a server that will proxy requests from Chat2Desk to Voximplant Kit and from Voximplant Kit to Chat2Desk.

Chat2Desc connection

To get API_TOKEN to use the Chat2Desk API, go to your Personal Account in the Settings section, then the API section and click Show:

To receive messages about new events from Chat2Desk, you need to set Callback URL. To do this, you need to make the following HTTP request:

curl -XPOST https://api.chat2desk.com/v1/webhooks \
-H "Authorization: {{YOUR_API_TOKEN}}" \
-H "Content-Type: application/json" \
--data '{"url": "{{YOUR_SERVER_HOST}}/chat2desc-incoming", "name": "Chat2desc-events-handler", "events": ["inbox"]}'

YOUR_API_TOKEN - API token to work with Chat2Desk API YOUR_SERVER_HOST - Host where your server will be accessible

Voximplant Kit connection

It is necessary to specify a separate server callback URL for Voximplant Kit in the custom channel settings, so Voximplant Kit will send its events to this callback URL:

PHP integration

For this integration, we need the following components:

  1. Configuration with details from accounts.
  2. HTTP client for working with API Voximplant Kit.
  3. HTTP client for working with API Chat2Desk.
  4. Database for storing information and chats.
  5. Voximplant Kit HTTP request handler.
  6. HTTP request handler from Chat2Desk.

Let's start with the application configuration. For configuration, we use the dotenv extension. An example of a .env file with configuration data:

File: .env

File: .env

KIT_ACCOUNT_NAME is the name of your Kit account.

KIT_API_TOKEN - API token for authentication in the Voximplant Kit service, can be obtained in the integration section.

KIT_CHANNEL_UUID - channel UUID of custom channel in Voximplant Kit. You can get the channel UUID in the custom channel settings in the uppermost Channel UUID field.

CHAT2DESC_API_TOKEN - API token for authentication in the Chat2Desk service.

Next, we initialize the HTTP client for the Voximplant Kit API:

File: /config.php

File: /config.php

Part 1

To work with the Voximplant Kit IM API, we use the SDK, its description can be found here.

Next, we initialize the HTTP client to work with the Chat2Desk API in the same config.php file:

File: /config.php

File: /config.php

Part 2

The description of the “Chat2DeskClient” class can be found at the link given at the end of this article.

Next, we initialize the component for storing information about chats:

File: /config.php

File: /config.php

Part 3

A description of the "Repository" class can be found at the link given at the end of this article.

Next, we initialize the service that will process events from Chat2Desc and Voximplant Kit:

Initialize a service to process events from Chat2Desc and Voximplant Kit

Initialize a service to process events from Chat2Desc and Voximplant Kit

Here are some code snippets from the Service.php class for event handling. Event handling from Voximplant Kit:

Handle events from Voximplant Kit

Handle events from Voximplant Kit

Handling events from Chat2Desc:

Handle events from Chat2Desc

Handle events from Chat2Desc

Next, let's start writing our server that will process HTTP requests from Chat2Desc and Voximplant Kit.

First of all, you need to authenticate in Voximplant Kit and then start the HTTP request handlers from Chat2Desc and Voximplant Kit.

File: /app.php

File: /app.php

Request handler from chat2desc-incoming:

Process Chat2Desc requests

Process Chat2Desc requests

Voximplant Kit Request Processor:

Process Voximplant Kit requests

Process Voximplant Kit requests

When creating a custom channel, Voximplant Kit sends a test GET request to the specified callback URL. Let's add a handler for a test request from Voximplant Kit:

Handle a test request

Handle a test request

Additional Information