> ## Documentation Index
> Fetch the complete documentation index at: https://koreai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring Custom Agent Integration

[Back to Agent Transfer Integrations](https://koreai.mintlify.site/ai-for-service/integrations/overview.md#agent-transfer)

The Custom Integration uses the BotKit SDK to configure agent transfer for any system not covered by a pre-built integration.

BotKit source code is available at [https://github.com/Koredotcom/BotKit](https://github.com/Koredotcom/BotKit).

***

## Prerequisites

* A fully functional AI Agent (example uses a Banking App)
* [BotKit SDK](https://github.com/Koredotcom/BotKit) downloaded from GitHub
* Node.js v10 or above — install from `https://nodejs.org/en/download/` and verify with `node -v`
* [NGROK](https://dl.equinox.io/ngrok/ngrok/stable) to simulate the callback server:
  * **Windows**: Download the zip, unzip, and run `ngrok.exe`
  * **Mac**: Run `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null` in Terminal, then run `brew cask install ngrok`
* A live agent platform (example uses [LiveChatInc.com](https://www.livechatinc.com/) — free 30-day trial available)

***

## Design and Configuration

1. Open Platform.

2. Select the app to configure for Agent Transfer.

3. Open or create a dialog task (for example, `Support Call Back`) and add an **Agent Transfer** node.

   ![Add Agent Transfer node](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img1-at-node.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=70b66551cb554b0284b183f3c2d965c9)

4. Enter a **Name** (for example, `LiveChat`) and **Description**. Click **Save**.

5. If you see a message about SDK not being configured, proceed — SDK configuration is covered below.

6. Go to **App Settings > Integration > Agent Transfer > Custom (BotKit)**.

7. In the **App Name** section, select an existing app or click **Create App** to create a new one.

   > [!NOTE]
   >
   > Note the **App ID**, **Client ID**, and **Client Secret** keys. **RS256 and RS512** JWT signing algorithms are **not supported** for Custom BotKit.

8. Enter the Callback URL:

   1. In a terminal, run `ngrok http 8003`.

   2. Copy the ngrok forwarding URL (format: `https://XXXXXXaa.ngrok.io`).

      ![NGROK forwarding URL](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img2-ngrok.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=0b339e224dcf14d863b6946920b7a813)

   3. Use this URL as the Callback URL and save.

   > [!NOTE]
   >
   > The ngrok forwarding URL changes on every restart. Update the Callback URL each time ngrok is restarted.

9. Open the dialog task and the agent transfer node to verify the configuration is saved. Select the required Events.

   ![Agent transfer node configuration](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img3-at-node-config.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=f9d8a21c0b58c44a178c5965d34d6ce9)

10. Get the LiveChat license code:
    1. Sign in to your LiveChat account.
    2. Go to **Settings** and select the **chat link**.
    3. Copy the license code from the URL (for example, from `https://lc.chat/now/104xx297/`, the code is `104xx297`).

11. Edit the BotKit SDK files:

    **`livechatapi.js`**

    * Set the `appId` and `appName` from your app.
    * This file contains the Kore Initialization, Send Message, and Get Message APIs. Add any new agent transfer APIs here.

    ![livechatapi.js](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img4-at-livechatapi.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=b9c491515bd9ac5481816a0ab7b1e8fe)

    **`config.json`**

    * Set `Client ID`, `Client Secret`, server ports, and the live agent license.
    * `Client ID` and `Client Secret` come from **Events and Extensions - Agent Transfer**.
    * The ngrok URL is the Callback URL — enter it as the URL field.
    * `liveagentlicense` is the LiveChat license code from the chat link.

    ![config.json](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img5-at-configjson.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=7e817e5f50213c652c61ac5f9d280011)

    **`LiveChat.js`**

    * Set the `appId` and `appName` from your app.

    ![LiveChat.js](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img6-at-livechat.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=4e2d55c90d1e8ddc76b1bd0593014396)

    **`app.js`**

    * Add: `sdk.registerBot(require('./LiveChat.js'))`
    * Remove any existing `sdk.registerBot` statements that aren't needed.

    ![app.js](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img7-at-appjs.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=d21ec74a465ea59f16382116ef1c100f)

***

## Execution

1. In a terminal, run the BotKit SDK:
   ```
   node app.js
   ```

2. Install any missing modules if errors appear:
   ```
   npm install <module-name>       # Windows
   sudo npm install <module-name>  # Mac
   ```

3. ngrok and Node.js will be running in separate terminals.

4. When a user initiates chat, the app transfers to an agent and notifies the user.

   ![Chat initiation](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img8-at-chat1.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=22d0c39d548f21361b8f72d9b93932e8)

5. The agent receives a notification on LiveChat.

   ![Agent receives notification](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img9-at-chat2.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=fbfade2bbfbe8d09d20da07e200d45fd)

6. The connection is established and the conversation continues.

   ![Connection established](https://mintcdn.com/koreai/XejbPbTVVStPIGXG/ai-for-service/integrations/agents/images/configure-agent-transfer-img10-at-chat3.png?fit=max\&auto=format\&n=XejbPbTVVStPIGXG\&q=85\&s=0e3d0e4f6dd91ec5b1046116b093f8c5)

***

## Events

> [!NOTE]
>
> The events and methods for sending messages between user, app, and agent are defined in `LiveChat.js`.

| Event / Method | Description |
| - | - |
| `on_user_message` | Triggered when a user sends a message. Sends it to the app via `sendBotMessage`. |
| `on_bot_message` | Triggered when the app sends a message. Delivers it to the user via `SendUserMessage`. |
| `on_agent_transfer` | Triggered when the agent transfer node fires. Connects to the agent via `connectToAgent`, which calls `initChat`. |
| `gethistory` | Provides the user's prior chat history with the app to the transferred agent. |
| `scheduleJob` | Polls for pending agent messages every 5 seconds via `getPendingMessages`. |
| `getPendingMessages` | Retrieves all pending messages from the agent and delivers them to the user. |
| `chat_closed` | Triggered when the agent closes the chat. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.