To connect the Intercom 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. For more information, go here. Also, you must have an Intercom account where you need to generate an API token to work with the Intercom API. To integrate with Intercom, you need to have a server that will proxy requests from Intercom to Voximplant Kit and vice versa.
Before we start creating a server, you need to connect the intercom and set the callback URL of the server in your personal account, where Intercom will send its events. To do this, go to the developer hub at Intercom.
Create a new application. Select the workspace where the application will run.
After you create a new application, go to the Authentication section, there you can find the Access Token.
Go to the Webhooks section. Enter your endpoint URL in the appropriate field.
In the Webhook topics section, select conversation.user.created conversation.user.replied. You can add more topics but the above should be mandatory.
Voximplant Kit connection
Specify a separate callback URL of the server for Voximplant Kit in the custom channel settings to allow Voximplant Kit to send its events to this callback URL.
For integration, we need the following components:
Configuration with details from accounts.
HTTP client for working with API Voximplant Kit.
HTTP client to work with Intercom API.
Database for storing information and chats.
HTTP request handler from Voximplant Kit.
Intercom HTTP request handler Let's start with the application configuration. For configuration, we use the dotenv extension. Example .env file with configuration data:
KIT_ACCOUNT_NAME - The name of your Voximplant 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.
INTERCOM_API_TOKEN - API token for authentication in the Intercom service.
INTERCOM_ADMIN_ID - This is the ID of the admin in the Intercom, used as an agent when replying to a message.
Next, we initialize the HTTP client for the Voximplant Kit IM 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 Intercom API in the same config.php file:
A description of the "IntercomClient" class can be found at the link given at the end of the 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 the article.
Next, we initialize the service that will process events from Intercom and Voximplant KIT:
Here are some code snippets from the Service.php class for event handling. Event processing from Voximplant Kit:
Event handling from intercom:
Next, let's start writing our server that will process HTTP requests from Intercom and Voximplant Kit.
First of all, it is necessary to pass authentication in Voximplant Kit and then start HTTP request handlers from Intercom and Voximplant Kit:
Intercom request handler:
Voximplant KIit 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: