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

# Configuring Custom Agent Integration

<Badge icon="arrow-left" color="gray">[Back to Agent Transfer Integrations](/ai-for-service/integrations/overview#agent-transfer)</Badge>

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.

   <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img1-at-node.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=32db1fb992588624b9adea976f889e2f" alt="Add Agent Transfer node" width="1366" height="768" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img1-at-node.png" />

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.</Note>

8. Enter the Callback URL:

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

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

      <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img2-ngrok.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=d2738345c3f0dd395709b4b13aa66aac" alt="NGROK forwarding URL" width="642" height="166" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img2-ngrok.png" />

   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.</Note>

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

   <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img3-at-node-config.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=0bf1d47cf83da4d97c629c6557e9ba28" alt="Agent transfer node configuration" width="1366" height="768" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img3-at-node-config.png" />

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.

    <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img4-at-livechatapi.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=09fd8fc35fa326b9d149e6fa33ce7962" alt="livechatapi.js" width="1072" height="343" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img4-at-livechatapi.png" />

    **`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.

    <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img5-at-configjson.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=8e67db6669586f23583aa712f544688a" alt="config.json" width="841" height="503" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img5-at-configjson.png" />

    **`LiveChat.js`**

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

    <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img6-at-livechat.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=c040ed1372ec73bd0adaa38c01b8b871" alt="LiveChat.js" width="1075" height="555" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img6-at-livechat.png" />

    **`app.js`**

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

    <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img7-at-appjs.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=a12b2925ec81ff133e1a43436fc6902e" alt="app.js" width="375" height="203" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img7-at-appjs.png" />

***

## 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.

   <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img8-at-chat1.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=6ed3ef2ca9a0dd4fb5fe4e4509a40c10" alt="Chat initiation" width="1649" height="826" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img8-at-chat1.png" />

5. The agent receives a notification on LiveChat.

   <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img9-at-chat2.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=34301b8eb24ae030bfc2d06b1ebb8ed0" alt="Agent receives notification" width="1660" height="619" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img9-at-chat2.png" />

6. The connection is established and the conversation continues.

   <img src="https://mintcdn.com/koreai-apis/mAsbFfJHEAX26r4Y/ai-for-service/integrations/agents/images/configure-agent-transfer-img10-at-chat3.png?fit=max&auto=format&n=mAsbFfJHEAX26r4Y&q=85&s=4ff3c30bdfae48d8033a6dc7e5b09157" alt="Connection established" width="1655" height="766" data-path="ai-for-service/integrations/agents/images/configure-agent-transfer-img10-at-chat3.png" />

***

## Events

<Note>The events and methods for sending messages between user, app, and agent are defined in `LiveChat.js`.</Note>

| 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.                                                                         |
