Custom channels: Chat2Desk
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 where 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.
Chat2Desk 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:
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:
- Configuration with details from accounts
- HTTP client for working with API Voximplant Kit
- HTTP client for working with API Chat2Desk
- Database for storing information and chats
- Voximplant Kit HTTP request handler
- HTTP request handler from Chat2Desk
Let's start with the application configuration. For configuration, we use the dotenv extension. An example of an .env file with configuration data:
KIT_ACCOUNT_NAME
- 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.
CHAT2DESK_API_TOKEN
- API token for authentication in the Chat2Desk service.
Next, let us initialize the HTTP client for the Voximplant Kit API:
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:
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:
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 Chat2Desk and Voximplant Kit:
Here are some code snippets from the Service.php class for event handling. Event handling from Voximplant Kit:
Handling events from Chat2Desk:
Next, let's start writing our server that will process HTTP requests from Chat2Desk and Voximplant Kit.
First of all, you need to authenticate in Voximplant Kit and then start the HTTP request handlers from Chat2Desk and Voximplant Kit.
Request handler from chat2desk-incoming:
Voximplant Kit Request Processor:
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: