NAV
shell

Introduction

Welcome to KeyReply Developer Docs V1! You can use our API and hooks to build your own solutions on top of the KeyReply system. This version is designed for integrating our live chat flow into your application.

Some of the things you can do in version 1 include:

Prerequisites

You must enable the "Developer" menu in Settings -> Developer. You can choose to enable only incoming requests or outgoing event hooks there.

How to Start

If your client has a development team and wants to create a service that connects to the KeyReply API, you need to:

  1. Enable the "Developer" menu in Settings -> Developer. 1-enable-developer-module
  2. Share the following information with their developer:
    • This documentation website.
    • Authentication key from "Settings" -> Developer.
    • KeyReply dashboard web URL, for their developers to debug.

Default API URL

The URL for the KeyReply API is:

For example:

If you have not enabled it, the API will return a 403 status with the following message:

{
  "errors": "Incoming request is disabled"
}

Authentication

Incoming Requests

Make sure to replace "x-api-key" key with your API key shown on dashboard.

# example request
curl "api_endpoint_here" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

# example request with idempotency key
curl "api_endpoint_here" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"
  -H "Idempotency-Key: kZmFzZ"

Without correct auth key, server will response with 401 status :

{
  "message": "Unathorized
}

if request is still on process, it will returned 409 with following message :

{
  "message": "Request already processed"
}

if you're surpassing rate limit, it will returned 423 with following message :

{
  "message": "You have requested too many times. Please wait a moment."
}

Authorization via API Keys

KeyReply uses API keys to authorize access to the API. KeyReply expects the API key to be included in all API requests to the server in a header, as stated in the examples.

KeyReply agents can add multiple API keys via the dashboard, and you should share at least one key with each vendor.

2-add-api-keys

Idempotent Requests

The API supports idempotency for safely retrying requests without accidentally performing the same operation twice. This feature is useful when an API call is disrupted in transit, and you do not receive a response. For example, if a request to send a message fails to respond due to a network connection error, you can retry the request with the same idempotency key to guarantee that no more than one message is created.

To perform an idempotent request, provide an additional Idempotency-Key: <key> header to the request.

Rate Limit

For security purposes, a request rate limit applies to each API key: 600 requests per 1 minute. The system will return an error if you surpass this limit.

Outgoing Requests

If you are using our event hook to send requests to your system for certain actions, please make sure to apply security measures to ensure all requests come from the KeyReply server.

Examples:

Virtual assistant (VA)

Use this endpoint for your visitor to send message to our Virtual Assistant (VA) and get a response back. You can parse the response according to the your application need. The response from VA is as configured on your dashboard settings (e.g content node setting, trigger setting, FAQ setting)

Please note that sending message to VA when visitor is under a livechat session is not supported yet. This will be updated shortly.

All requests for VA begin with /virtual-assistant

Send message

curl -X POST [API_URL]/virtual-assistant/message
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{
    "sender": {
      "id": "613b5897-062e-40ba-bf49-ebda02a95475",
    },
    "recipient": {
      "id": "app.keyreply.com"
    },
    "message": {
      "text": "hi",
      "isPreview": false,
      "id": "ckrg7bcrt00043h6cxm2to7ot"
    }
  }
  '

Successful request will return the following JSON structure. You should parse the content inside response according to your application needs. Every response might contain multiple contents from VA.

{
  "response": [
    {
      "content": [
        {
          "text": "Welcome to KeyReply. How can I help you today?",
          "buttons": [
            {
              "text": "Service Information",
              "type": "event",
              "event": "goto",
              "data": "appointment booking_choose department"
            },
            {
              "text": "Talk to an agent",
              "type": "event",
              "event": "goto",
              "data": "singpass_login"
            },
            {
              "text": "Appointment Booking",
              "type": "event",
              "event": "goto",
              "data": "appointment booking_welcome message"
            }
          ]
        }
      ],
      "listStyle": null,
      "quickReplies": [
        {
          "text": "Myinfo",
          "event": "goto",
          "data": "singpass_myinfo"
        },
        {
          "text": "Login",
          "event": "goto",
          "data": "singpass_login"
        }
      ],
      "options": {
        "disableTextInput": false,
        "feedbackCollectionMode": "default",
        "nodeId": "conversation_start"
      },
      "meta": {
        "hideSuggestions": false,
        "lang": "default"
      }
    }
  ]
}

Send message to virtual assistant and get a response based on settings configured on your KeyReply dashboard.

Example use cases:

HTTP Request

POST [API_URL]/virtual-assistant/message

Body

Parameter Mandatory Description Example Value
sender.id required unique visitor id from your application VISITOR007
recipient.id required identifier from your application jamesbond@yoursystem.com
message.text required the chat / text to be send Hello world!
message.isPreview optional whether VA should use preview content (if using maker checker module) true
message.id optional the chat id from your application ckrg7bcrt00043h6cxm2to7ot

Send postback message

curl -X POST [API_URL]/virtual-assistant/message
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{
    "id": "ckrg6vjyo00003h6cpaxlqo9i",
    "sender": {
      "id": "90d2874e-60f3-4568-88f6-4f59120206a6",
      "session_id": "d4020f73-2d0c-409d-8198-4f7b6c350765"
    },
    "recipient": {
      "id": "app.keyreply.com"
    },
    "postback": {
      "event": "goto",
      "data": "conversation_start",
      "isPreview": false,
      "options": {}
    }
  }'

Successful request will return the following JSON structure. You should parse the content inside response according to your application needs. Every response might contain multiple contents from VA.

{
  "response": [
    {
      "content": [
        {
          "text": "Welcome to KeyReply. How can I help you today?",
          "buttons": [
            {
              "text": "Service Information",
              "type": "event",
              "event": "goto",
              "data": "appointment booking_choose department"
            },
            {
              "text": "Talk to an agent",
              "type": "event",
              "event": "goto",
              "data": "singpass_login"
            },
            {
              "text": "Appointment Booking",
              "type": "event",
              "event": "goto",
              "data": "appointment booking_welcome message"
            }
          ]
        }
      ],
      "listStyle": null,
      "quickReplies": [
        {
          "text": "Myinfo",
          "event": "goto",
          "data": "singpass_myinfo"
        },
        {
          "text": "Login",
          "event": "goto",
          "data": "singpass_login"
        }
      ],
      "options": {
        "disableTextInput": false,
        "feedbackCollectionMode": "default",
        "nodeId": "conversation_start"
      },
      "meta": {
        "hideSuggestions": false,
        "lang": "default"
      }
    }
  ]
}

Send postback message to virtual assistant and get a response back. Postback message is type of request to execute an event. This is used usually after visitor select button or quick replies.

For example, if you want visitor to get greetings from chatbot, you can request for event "go to" with data "conversational_start". This will make VA response with "conversational_start" content to your application. if you want visitor to be escalated to livechat, you can request for event "handover_start". This will make VA starts the livechat flow and response with appropriate content node.

For full list of events and data, you might want to check your dashboard.

Example use cases:

HTTP Request

POST [API_URL]/virtual-assistant/message

Body

Parameter Mandatory Description Example Value
sender.id required unique visitor id from your application VISITOR007
recipient.id required identifier from your application jamesbond@yoursystem.com
postback.event required event to be executed goto
postback.data optional data for the event conversation_start
postback.isPreview optional whether VA should use preview content (if using maker checker module) true
postback.options optional additional options ckrg7bcrt00043h6cxm2to7ot

Sessions

Sessions are chat session data initiated by visitor to the KeyReply webchat.

All requests for visitor data begin with /sessions.

Get all sessions

curl "[API_URL]/sessions?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 2175,
  "results": [
    {
      "id": 45501,
      "sessionId": "d5dfee60-2137-4cb2-b84a-3c3ddc106dc3",
      "stateId": "8a085c67-f8d7-4287-b6e3-e20faff1fdb3",
      "statePartitionKey": "localhost",
      "createdAt": "2022-08-23T05:00:51.466Z",
      "updatedAt": "2022-08-23T05:01:39.923Z",
      "expireAt": "2022-08-23T05:01:37.916Z"
    },
    {
      "id": 45502,
      "sessionId": "5baf2927-48be-43dd-96a9-efb6114fad7c",
      "stateId": "26846d9b-2e50-47f2-a7d7-f28483eef07b",
      "statePartitionKey": "localhost",
      "createdAt": "2022-08-23T05:01:40.397Z",
      "updatedAt": "2022-08-23T05:04:32.715Z",
      "expireAt": "2022-08-23T05:04:30.713Z"
    }
  ]
}

This endpoint retrieves all sessions on specified conditions.

Example use cases:

HTTP Request

GET [API_URL]/sessions

Query Parameters

Parameter Mandatory Default Description
fromDate required ISO 8601 format (ex: 2022-08-01)
toDate required ISO 8601 format (ex: 2022-08-31)
sort optional desc "asc" (ascending) or "desc" (descending)
limit optional 100 max number of data that will be returned
offset optional 0 offset of data that will be returned
stateId optional filter sessions by state id

Get a specific session

curl "[API_URL]/sessions/d5dfee60-2137-4cb2-b84a-3c3ddc106dc3" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "id": 45501,
  "sessionId": "d5dfee60-2137-4cb2-b84a-3c3ddc106dc3",
  "stateId": "8a085c67-f8d7-4287-b6e3-e20faff1fdb3",
  "statePartitionKey": "localhost",
  "createdAt": "2022-08-23T05:00:51.466Z",
  "updatedAt": "2022-08-23T05:01:39.923Z",
  "expireAt": "2022-08-23T05:01:37.916Z"
}

This endpoint retrieves a specific session.

Example use cases:

HTTP Request

GET [API_URL]/session/:sessionId

End / renew chat session

curl -X POST [API_URL]/sessions/720e983c-9e51-48a2-9765-812bc46dfaf8/localhost/end
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "id": 49418,
  "sessionId": "720e983c-9e51-48a2-9765-812bc46dfaf8",
  "stateId": "f7f44a01-29ed-409e-9730-5eb3251be4c0",
  "statePartitionKey": "localhost",
  "createdAt": "2022-09-23T06:09:38.460Z",
  "updatedAt": "2022-09-23T06:09:38.539Z",
  "expireAt": "2023-03-22T06:09:38.539Z"
}

Use this endpoint to force a visitor to end their chat session and get new session

Example use cases:

HTTP Request

POST [API_URL]/sessions/:sessionId/:PartitionKey

Path Parameters

Parameter Example Description
sessionId 720e983c-9e51-48a2-9765-812bc46dfaf8 -
PartitionKey localhost -

Visitor

Visitor data consists of profile information about visitors, similar to what is shown on the "Visitors" tab. This data includes all the information captured on content nodes or during chat sessions.

The data that can be displayed via the visitor API is configurable.

4-manage-visitor-data

All requests for visitor data should begin with /states.

If you are using a statically typed language, please be aware that the data returned from this API might have different fields for each request, depending on what user configured on Dashboard.

Get all visitors

curl "[API_URL]/states?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 15,
  "results": [
    {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "localhost",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "userQueryTopic": "department A"
    }
  ]
}

This endpoint retrieves all states on specified conditions, similar to what is shown on KeyReply Dashboard -> visitor tab.

Example use cases:

HTTP Request

GET [API_URL]/states

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
PartitionKey optional filter by PartitionKey keyreply.com
channel optional filter by channel webchat

Get specific visitor

curl "[API_URL]/states/5db0d549-c45a-439d-af6a-ab91aa85eaf0" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
    "RowKey": "5db0d549-c45a-439d-af6a-ab91aa85eaf0",
    "PartitionKey": "localhost",
    "last_modified": "2022-09-21T06:20:14.153Z",
    "date_created": "2022-09-21T04:30:45.472Z",
    "channel": "webchat",
    "entities": "{}",
    "department": "00000000-0000-0000-0000-000000000000",
    "source": "webchat",
    ...
}

This endpoint retrieves a single object of visitor (state)

Example use cases:

HTTP Request

GET [API_URL]/states/:PartitionKey/:RowKey

Path Parameters

Parameter Description Example
PartitionKey domain / origin of the widget where visitor open the webchat keyreply.com
RowKey the rowkey of the visitor webchat

Update visitor data

curl -X POST [API_URL]/localhost/2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e/private_variables
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{"name":"John Doe"}'

Successful request will return the following JSON structure:

{
  "RowKey": "2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e",
  "PartitionKey": "localhost",
  "externalData": {
    "name": "John Doe"
  },
  ... // other visitor's existing data
}

Set a visitor data. For security purpose, all of your data will be located under "externalData".

Example use cases:

HTTP Request

POST [API_URL]/states/:PartitionKey/:RowKey/private_variables

Path Parameters

Parameter Example Description
RowKey 2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e The state RowKey
PartitionKey localhost the state PartitionKey

Body

Parameter Mandatory Description Example Value
[key] required any { key: value } can be stored into visitor data, under key externalData [value]

Interaction

Interactions are data containing chat messages as shown on the webchat widget.

All requests for interactions data begin with /interactions

Get interaction

curl "[API_URL]/interactions?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 171,
  "results": [
    {
      "RowKey": "cl8b75ubl0049n6oq1758hp4x",
      "PartitionKey": "localhost",
      "last_modified": "2022-09-21T05:41:02.529Z",
      "date_created": "2022-09-21T05:41:02.529Z",
      "source": "webchat",
      "type": "reply",
      "user_id": "2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e",
      "session": "59e6e15f-080d-4007-82bc-3591b9808c96",
      "data": {
        "content": [
          {
            "text": "Agent Yudha has joined the chat.",
            "buttons": []
          }
        ],
        "listStyle": null,
        "options": {
          "disableTextInput": false,
          "feedbackCollectionMode": "default",
          "nodeId": "handover_livechat_agent_join"
        },
        "meta": {
          "hideSuggestions": false,
          "lang": "default"
        }
      }
    }
  ]
}

This endpoint retrieves all interactions based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/interactions

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
type optional filter by interaction type message
PartitionKey optional filter by PartitionKey keyreply.com
userId optional filter by user id 5db0d549-c45a-439d-af6a-ab91aa85eaf0
session optional filter by session id d5dfee60-2137-4cb2-b84a-3c3ddc106dc3

Dashboard Users

This section details the data related to users on the KeyReply dashboard.

All requests associated with dashboard users should begin with /dashboard-users.

Get All Dashboard Users

curl "[API_URL]/dashboard-users" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

A successful request will return the following JSON structure:

{
  "count": 26,
  "results": [
    {
      "email": "agent@keyreply.com",
      "name": "John Doe",
      "data": "{\"app_metadata\":{\"departments\":[\"customer service\",\"claims\"],\"permissions\":[\"admin\"],\"roles\":[\"admin\"]},\"user_metadata\":{\"name\":\"John Doe\"}}",
      "livechat_status": "OFFLINE",
      "dashboard_status": "ONLINE",
      "livechat_settings": {
        "queues": [
            "customer service"
        ],
        "limit": 3
      }
    },
    ...
  ]
}

This endpoint fetches all dashboard users based on the provided filter conditions.

HTTP Request

GET [API_URL]/dashboard-users

Query Parameters

Parameter Mandatory Default Description Example
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
email optional Filter by user's email "agent@keyreply.com"
name optional Filter by user's name "OFFLINE"
livechat_status optional Filter by live chat status "OFFLINE"
dashboard_status optional Filter by dashboard status "OFFLINE"

Agent status

This section contains data related to live chat agent statuses. The default statuses are "ONLINE" and "OFFLINE". Additional statuses may be configured through the KeyReply dashboard. All requests for this data must begin with /agent-status-sessions.

Get all agent status sessions

curl "[API_URL]/agent-status-sessions?fromDate=2022-09-01&toDate=2022-09-30" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 5,
  "results": [
    {
      "id": 29395,
      "agentId": "agent@keyreply.com",
      "agent_auth_type": "KEYCLOAK",
      "startTime": "2022-09-21T05:40:35.410Z",
      "endTime": "2022-09-21T05:56:46.037Z",
      "status": "ONLINE",
      "createdAt": "2022-09-21T05:40:35.447Z",
      "updatedAt": "2022-09-21T05:56:46.039Z"
    },
    ...
  ]
}

This endpoint retrieves all agent status based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/agent-status-sessions

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
agentId optional filter by agentId "agent@keyreply.com"
status optional filter by status "OFFLINE"

Livechat

Livechat sessions are chat sessions that goes into a livechat mode. This is similar to data that shown on "Livechat" page.

All requests for livechat session data begin with /livechatsessions

Get all livechat sessions

# Get all livechat sessions on certain date
curl "[API_URL]/livechatsessions?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

# Get all livechat sessions whom waiting for assignment
curl "[API_URL]/livechatsessions?fromDate=2022-08-01&toDate=2022-08-31&waiting_for_assignment=true" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

# Get all resolved livechat sessions
curl "[API_URL]/livechatsessions?fromDate=2022-08-01&toDate=2022-08-31&resolved=true" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 1,
  "results": [
    {
      "meta": {},
      "agents": ["agent@keyreply.com"],
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:a304194d-e301-4d49-8910-84d3561852ac"
      ],
      "status": "pending",
      "resolved": false,
      "formData": {
        "channel": "Web Chat"
      },
      "RowKey": "cl8e3ou5o001jp4oqadvzdc8u",
      "PartitionKey": "localhost",
      "date_created": "2022-09-23T06:27:08.845Z",
      "last_modified": "2022-09-23T06:27:09.242Z",
      "user_id": "a304194d-e301-4d49-8910-84d3561852ac",
      "sessionId": "3257b6ed-7751-4fce-b37e-b3a1c452799b",
      "startQueueTime": "2022-09-23T06:27:08.845Z",
      "startResolveTime": "2022-09-23T06:27:08.845Z",
      "endResolveTime": null,
      "endedBy": null,
      "department": "00000000-0000-0000-0000-000000000000",
      "provider": "keyreply",
      "waiting_for_assignment": true
    }
  ]
}

This endpoint retrieves all livechatsessions based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/livechatsessions

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
resolved optional filter by resolved true
user_id optional filter by user id (visitor RowKey) 5db0d549-c45a-439d-af6a-ab91aa85eaf0
waiting_for_assignment optional filter by waiting_for_assignment false
sessionId optional filter by session id 3257b6ed-7751-4fce-b37e-b3a1c452799b

Get all livechat departments

curl "[API_URL]/livechatsessions/departments" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 2,
  "result": [
    {
      "id": "88cfe361-05e6-4aba-b408-df776109ebf3",
      "name": "customer service",
      "createdAt": "2021-12-13T06:31:21.701Z",
      "updatedAt": "2021-12-13T06:31:21.701Z"
    },
    {
      "id": "64b4942f-264e-4427-9beb-ed4012c31adf",
      "name": "customer service priority",
      "createdAt": "2021-12-15T02:44:10.368Z",
      "updatedAt": "2021-12-15T02:44:10.368Z"
    }
  ]
}

This endpoint retrieves all departments without any limits or offsets.

Example use cases:

HTTP Request

GET [API_URL]/livechatsessions/departments

Query Parameters

There is no query parameter for this API.

Get specific chat session

curl "[API_URL]/livechatsessions/cl8e3ou5o001jp4oqadvzdc8u" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
    "interactions": [{
            "PartitionKey": "localhost",
            "RowKey": "cl8e3otzl00043b6qsci55alf",
            "user_id": "a304194d-e301-4d49-8910-84d3561852ac",
            "session": "3257b6ed-7751-4fce-b37e-b3a1c452799b",
            "type": "postback",
            "source": "webchat",
            "date_created": "2022-09-23T06:27:08.746Z",
            "Timestamp": "2022-09-23T06:27:08.746Z",
            "data": {
                "content": [{
                    "event": "goto",
                    "data": "handover_livechat_start",
                    "postbackText": "Proceed"
                }]
            }
        },
        ...
    ],
    ...
}

This endpoint retrieves a specific livechatsession.

Example use cases:

HTTP Request

GET [API_URL]/livechatsessions/:RowKey

Join a livechat

curl -X POST [API_URL]/livechatsessions/2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e/join
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{"agentName":"John Doe", "agentEmail":"john@keyreply.com", "agentId" : "Y6YXNk"}'

Successful request will return the following JSON structure:

{
    "interactions": [
        ...
    ],
    "meta": {},
    "agents": [
        "loremipsum@keyreply.com"
    ],
    "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:a304194d-e301-4d49-8910-84d3561852ac"
    ],
    "status": "attending",
    "resolved": false,
    "formData": {
        "channel": "Web Chat"
    },
    "RowKey": "cl8e3ou5o001jp4oqadvzdc8u",
    "PartitionKey": "localhost",
    "date_created": "2022-09-23T06:27:08.845Z",
    "last_modified": "2022-09-23T06:46:36.444Z",
    "user_id": "a304194d-e301-4d49-8910-84d3561852ac",
    "sessionId": "3257b6ed-7751-4fce-b37e-b3a1c452799b",
    "startQueueTime": "2022-09-23T06:27:08.845Z",
    "startResolveTime": "2022-09-23T06:46:36.443Z",
    "endResolveTime": null,
    "endedBy": null,
    "department": "00000000-0000-0000-0000-000000000000",
    "provider": "keyreply",
    "waiting_for_assignment": false
}

Set your agent to join a livechat session

Example use cases:

HTTP Request

POST [API_URL]/livechatsessions/:RowKey/join

Path Parameters

Parameter Example Description
RowKey cl8e3ou5o001jp4oqadvzdc8u The livechatsession RowKey

Body

Parameter Mandatory Description Example Value
agentId required unique agent fd from your system AGENT007
agentName required agent name to be shown on join livemessage chat James Bond
agentEmail required agent name to be shown on audit page jamesbond@yoursystem.com

Reply livechat

curl -X POST [API_URL]/livechatsessions/2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e/reply
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{"agentName":"John Doe", "agentEmail":"john@keyreply.com", "agentId" : "Y6YXNk", "text":"how can I help?"}'

Successful request will return the following JSON structure:

// @TODO : update this
{
  "isInserted": true,
  "pid": 20344,
  "podId": "wealthy_red_swordfish"
}

Reply to a livechat session

Example use cases:

HTTP Request

POST [API_URL]/livechatsessions/:RowKey/reply

Path Parameters

Parameter Example Description
RowKey cl8e3ou5o001jp4oqadvzdc8u The livechatsession RowKey

Body

Parameter Mandatory Description Example Value
agentId required unique agent fd from your system AGENT007
agentName required agent name to be shown on join livemessage chat James Bond
agentEmail required agent name to be shown on audit page jamesbond@yoursystem.com
message required the chat / text to be send Hello world!

End a livechat

curl -X POST [API_URL]/livechatsessions/2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e/end
  -H "Content-Type: application/json"  \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -d '{"agentName":"John Doe", "agentEmail":"john@keyreply.com", "agentId" : "Y6YXNk", "endedBy":"agent"}'

Successful request will return the following JSON structure:

{
    "interactions": [{
            "PartitionKey": "localhost",
            "RowKey": "cl8e3otzl00043b6qsci55alf",
            "user_id": "a304194d-e301-4d49-8910-84d3561852ac",
            "session": "3257b6ed-7751-4fce-b37e-b3a1c452799b",
            "type": "postback",
            "source": "webchat",
            "date_created": "2022-09-23T06:27:08.746Z",
            "Timestamp": "2022-09-23T06:27:08.746Z",
            "data": {
                "content": [{
                    "event": "goto",
                    "data": "handover_livechat_start",
                    "postbackText": "Proceed"
                }]
            }
        },
        ...
    ],
    ...
}

End a livechat session and close the green banner on the webchat

Example use cases:

HTTP Request

POST [API_URL]/livechatsessions/:RowKey/end

Path Parameters

Parameter Example Description
RowKey cl8e3ou5o001jp4oqadvzdc8u The livechatsession RowKey

Body

Parameter Mandatory Description Example Value
agentId required unique agent fd from your system AGENT007
agentName required agent name to be shown on join livemessage chat James Bond
agentEmail required agent name to be shown on audit page jamesbond@yoursystem.com
endedBy optional who ended this chat ("agent" or "system"). default to "agent" system

Send image / file to a chat

curl -X POST [API_URL]/livechatsessions/2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e/send-file
  -H "Content-Type: multipart/form-data" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f" \
  -F "file=@/path/to/file" \
  -F "text=hello" \
  -F "agentName":"John Doe"
  -F "agentEmail":"john@keyreply.com" \
  -F "agentId" : "Y6YXNk"

Successful request will return the following JSON structure:

{
  "isInserted": true,
  "pid": 6213,
  "podId": "gleaming_bronze_kiwi"
}

Send file / image to a livechat session

Example use cases:

HTTP Request

POST [API_URL]/livechatsessions/:RowKey/send-file

Path Parameters

Parameter Example Description
RowKey cl8e3ou5o001jp4oqadvzdc8u The livechatsession RowKey

Body

Parameter Mandatory Description Example Value
agentId required unique agent fd from your system AGENT007
agentName required agent name to be shown on join livemessage chat James Bond
agentEmail required agent name to be shown on audit page jamesbond@yoursystem.com
file required File content

Retrieve image / file from user

curl -X GET [API_URL]/request-file?blobName=files/uploads/temp/c1d6abb0-7baa-4d84-a8b8-3967287abc9e/dummy-img.jpg \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "url": "https://yourkeyreplyserver.com/files/uploads/temp/c1d6abb0-7baa-4d84-a8b8-3967287abc9e/dummy-img.jpg?st=2023-02-16T02%3A40%3A42Z&se=2023-02-16T04%3A40%3A42Z&sp=r&sv=2018-03-28&sr=b&sig=z7ydJ7IMYy5TUHMtpECIo5lR8cN63va7Vr0WqeN5WIY%3D"
}

Retrieve the file url from image / file sent by user to your system. Accessing the url directly (ex: ttps://yourkeyreplyserver.com/files/uploads/temp/c1d6abb0-7baa-4d84-a8b8-3967287abc9e/dummy-img.jpg) without the additional metada like above might result to not authenticated error.

Example use cases:

HTTP Request

GET [API_URL]/livechatsessions/request-file

Query Parameters

Parameter Example Description
blobName files/uploads/temp/c1d6abb0-7baa-4d84-a8b8-3967287abc9e/dummy-img.jpg the blobName or URL found in the user chat

Chat Events

Chat events are data containing all events that happen during a chat session. This is a similar data that shown on "Visitor" tab -> "Show visitor interactions"

All requests for events data begin with /events

Get all events

curl "[API_URL]/events?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 26402,
  "results": [
    {
      "RowKey": "cl7a99ayh00xgk8oq37ddfk22",
      "PartitionKey": "localhost",
      "last_modified": "2022-08-26T09:12:14.778Z",
      "date_created": "2022-08-26T09:12:14.778Z",
      "data": "handover_livechat_agent_join",
      "event": "GOTO",
      "page_id": "localhost",
      "source": "webchat",
      "user_id": "78c82d51-b89a-4c32-94ec-b872718d656c",
      "session": "78c82d51-b89a-4c32-94ec-b872718d656c",
      "from": "CS_Help_livechat_SMS_Auto"
    },
    {
      "RowKey": "cl7a99a9d00x0k8oqa8ti57bg",
      "PartitionKey": "localhost",
      "last_modified": "2022-08-26T09:12:13.874Z",
      "date_created": "2022-08-26T09:12:13.874Z",
      "data": "handover_livechat_agent_join",
      "event": "GOTO",
      "page_id": "localhost",
      "source": "webchat",
      "user_id": "616610a9-5299-4e0c-a244-026f09f76a40",
      "session": "616610a9-5299-4e0c-a244-026f09f76a40",
      "from": "handover_livechat_wait"
    }
  ]
}

This endpoint retrieves all events based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/events

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
event optional filter by event name message
PartitionKey optional filter by PartitionKey keyreply.com
userId optional filter by user id 5db0d549-c45a-439d-af6a-ab91aa85eaf0
session optional filter by session id d5dfee60-2137-4cb2-b84a-3c3ddc106dc3

Ratings

Ratings are data containing rating that given by visitor at the end of the chat.

All requests for ratings data begin with /ratings

Get all ratings

curl "[API_URL]/ratings?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 1,
  "results": [
    {
      "RowKey": "cl3p7b0x9001an9oq9xeg0fh5",
      "PartitionKey": "AIA",
      "last_modified": "2022-05-28T01:35:19.150Z",
      "date_created": "2022-05-28T01:35:19.150Z",
      "rating": 1,
      "user": "74bff792-baf9-49f0-8e0e-af9cf103e5ab",
      "rating_comment": null,
      "sessionId": "369cd0bb-f548-44e7-90b5-2bea538bc205",
      "category": null,
      "livechatsession_id": "cl3p7alve000pn9oq0r900u9x"
    }
  ]
}

This endpoint retrieves all ratings based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/ratings

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
rating optional filter by rating 1
userId optional filter by user id 5db0d549-c45a-439d-af6a-ab91aa85eaf0

Form results

Form results are data containing the result of form from form builder (not from the post livechat) that visitor filled in. This is similar data as shown on "Editor" -> "Form" -> "Results"

All requests for Form results data begin with /form-results

Get Form results

curl "[API_URL]/form-results?fromDate=2022-08-01&toDate=2022-08-31" \
  -H "x-api-key: 9cac117e-d211-4193-9068-74ec449011f"

Successful request will return the following JSON structure:

{
  "count": 171,
  "results": [
    {
      "RowKey": "cl8b75ubl0049n6oq1758hp4x",
      "PartitionKey": "localhost",
      "last_modified": "2022-09-21T05:41:02.529Z",
      "date_created": "2022-09-21T05:41:02.529Z",
      "source": "webchat",
      "type": "reply",
      "user_id": "2c6a0cd1-863f-4e7e-bc7d-fcc3d4b34f9e",
      "session": "59e6e15f-080d-4007-82bc-3591b9808c96",
      "data": {
        "content": [
          {
            "text": "Agent Yudha has joined the chat.",
            "buttons": []
          }
        ],
        "listStyle": null,
        "options": {
          "disableTextInput": false,
          "feedbackCollectionMode": "default",
          "nodeId": "handover_livechat_agent_join"
        },
        "meta": {
          "hideSuggestions": false,
          "lang": "default"
        }
      }
    }
  ]
}

This endpoint retrieves all form results based on specified conditions

Example use cases:

HTTP Request

GET [API_URL]/form-results

Query Parameters

Parameter Mandatory Default Description Example
fromDate required ISO 8601 format 2022-08-01
toDate required ISO 8601 format 2022-08-31
sort optional desc "asc" (ascending) or "desc" (descending) desc
limit optional 100 max number of data that will be returned 10
offset optional 0 offset of data that will be returned 10
formId optional filter by form-id d5dfee60-2137-4cb2-b84a-3c3ddc106dc3
userId optional filter by user id 5db0d549-c45a-439d-af6a-ab91aa85eaf0
sessionId optional filter by session id d5dfee60-2137-4cb2-b84a-3c3ddc106dc3

Event Hooks

This section describes all the events that will send a request to the specified endpoint. You can provide one request URL for all events via "Settings -> Developer." The URL must contain the full protocol, such as "https://mysite.com/webhook." When an event is triggered, our system will send a POST request to the specified endpoint.

Every request body contains at least four JSON keys: "id", "event", "payload", "sentAt".

Parameter Description Example
id ID of the payload, used for checking idempotency (ensuring the same request is not sent multiple times) cledva3j10014088z0dtj0f8s
sentAt The time (ISO string format) when the request was sent 2023-08-04T03:16:56.937Z
event Name of the event "handover:afterLivechatSessionEnded"
payload Data object related to the events. Different events might contain various sets of data {RowKey: "...", ...}

Getting started

To get started, please configure the outgoing request section in the developer module.

3-add-event-hooks

Notes

4-manage-visitor-data

When a visitor sends a text message

Triggered when:

Example use cases:

Payload :

{
  "id": "clkw0kqgb001cw3bp53gq5gl7",
  "event": "bot:beforeTextHandler",
  "payload": {
    "visitor": {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "keyreply.com",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0"
    },
    "text": "talk to agent"
  },
  "sentAt": "2023-08-04T03:16:17.771Z"
}

After an agent changes status

Triggered when:

Example use cases:

Payload :

{
  "id": "clkw0lko9002lw3bp53qf2v8j",
  "event": "handover:agentChangedStatus",
  "payload": {
    "agent": "agent@keyreply.com",
    "status": "OFFLINE",
    "startTime": "2023-08-04T03:16:56.829Z",
    "departments": ["department A", "department B"],
    "previousStatus": "ONLINE"
  },
  "sentAt": "2023-08-04T03:16:56.937Z"
}

After a visitor requests a live chat

Triggered when:

Example use cases:

Payload :

{
  "id": "clkw0ktxa001xw3bpewv55oiy",
  "event": "handover:afterUserRequestedLivechat",
  "payload": {
    "visitor": {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "localhost",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "userQueryTopic": "department A"
    },
    "livechat": {
      "RowKey": "clkw0ktug001vw3bp5soc694a",
      "PartitionKey": "localhost",
      "startQueueTime": "2023-08-04T03:16:22.170Z",
      "startResolveTime": "2023-08-04T03:16:22.171Z",
      "agents": [],
      "date_created": "2023-08-04T03:16:22.171Z",
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:e229a5cd-8bfc-44d3-99cc-589dcc8af1c6"
      ],
      "resolved": false,
      "user_id": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "department": "00000000-0000-0000-0000-000000000000",
      "sessionId": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "waiting_for_assignment": true,
      "status": "pending",
      "formData": {
        "channel": "Web Chat"
      },
      "provider": "keyreply"
    }
  },
  "sentAt": "2023-08-04T03:16:22.270Z"
}

After an agent joins a live chat

Triggered when:

Example Use Cases:

Payload :

{
  "id": "clkw0kw0l0025w3bp21cq5i3m",
  "event": "handover:afterAgentJoinedLivechat",
  "payload": {
    "visitor": {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "localhost",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "userQueryTopic": "department A"
    },
    "livechat": {
      "meta": {},
      "agents": ["agent@keyreply.com"],
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:e229a5cd-8bfc-44d3-99cc-589dcc8af1c6"
      ],
      "status": "attending",
      "resolved": false,
      "formData": {
        "channel": "Web Chat"
      },
      "RowKey": "clkw0ktug001vw3bp5soc694a",
      "PartitionKey": "localhost",
      "date_created": "2023-08-04T03:16:22.171Z",
      "last_modified": "2023-08-04T03:16:24.406Z",
      "user_id": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "sessionId": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "startQueueTime": "2023-08-04T03:16:22.172Z",
      "startResolveTime": "2023-08-04T03:16:24.406Z",
      "endResolveTime": null,
      "endedBy": null,
      "department": "00000000-0000-0000-0000-000000000000",
      "provider": "keyreply",
      "waiting_for_assignment": false
    }
  },
  "sentAt": "2023-08-04T03:16:24.981Z"
}

After an agent accepted a livechat invitation

Triggered when:

Payload :

{
  "id": "clkw0kw0l0025w3bp21cq5i3m",
  "event": "handover:afterAgentAcceptedInvitation",
  "payload": {
    "visitor": {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "localhost",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "userQueryTopic": "department A"
    },
    "livechat": {
      "meta": {},
      "agents": ["agent@keyreply.com", "agent2@keyreply.com"],
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:e229a5cd-8bfc-44d3-99cc-589dcc8af1c6"
      ],
      "status": "attending",
      "resolved": false,
      "formData": {
        "channel": "Web Chat"
      },
      "RowKey": "clkw0ktug001vw3bp5soc694a",
      "PartitionKey": "localhost",
      "date_created": "2023-08-04T03:16:22.171Z",
      "last_modified": "2023-08-04T03:16:24.406Z",
      "user_id": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "sessionId": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "startQueueTime": "2023-08-04T03:16:22.172Z",
      "startResolveTime": "2023-08-04T03:16:24.406Z",
      "endResolveTime": null,
      "endedBy": null,
      "department": "00000000-0000-0000-0000-000000000000",
      "provider": "keyreply",
      "waiting_for_assignment": false
    }
  },
  "sentAt": "2023-08-04T03:16:24.981Z"
}

After live chat session ends

Triggered when:

Example use cases:

Payload :

{
  {
  "id": "clkw0le1t002iw3bpdnsagsoz",
  "event": "handover:afterLivechatSessionEnded",
  "payload": {
    "visitor": {
      "RowKey": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "PartitionKey": "localhost",
      "session_id": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "userQueryTopic": "department A"
    },
    "livechat": {
      "meta": {},
      "agents": [
        "agent@keyreply.com"
      ],
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:e229a5cd-8bfc-44d3-99cc-589dcc8af1c6"
      ],
      "status": "resolved",
      "resolved": true,
      "formData": {
        "channel": "Web Chat"
      },
      "RowKey": "clkw0ktug001vw3bp5soc694a",
      "PartitionKey": "localhost",
      "date_created": "2023-08-04T03:16:22.171Z",
      "last_modified": "2023-08-04T03:16:48.282Z",
      "user_id": "e229a5cd-8bfc-44d3-99cc-589dcc8af1c6",
      "sessionId": "c98817d2-ed3b-4162-b865-bbe66ae831a0",
      "startQueueTime": "2023-08-04T03:16:22.172Z",
      "startResolveTime": "2023-08-04T03:16:24.406Z",
      "endResolveTime": "2023-08-04T03:16:48.282Z",
      "endedBy": "agent",
      "department": "00000000-0000-0000-0000-000000000000",
      "provider": "keyreply",
      "waiting_for_assignment": false
    }
  },
    "sentAt": "2023-08-04T03:16:48.353Z"
  }
}

After a livechat is escalated

Triggered when:

Example use cases:

Payload information:

Payload :

{
  "id": "clos331xj005bw0bq7phx0upq",
  "event": "handover:afterLivechatSessionEscalated",
  "payload": {
    "visitor": {
      "userQueryTopic": "department B",
      "RowKey": "9f56c9ee-af55-4ff2-bc72-66757fe42903",
      "PartitionKey": "localhost",
      "session_id": "a46becd6-b456-4826-9123-7ca5dc413581"
    },
    "livechat": {
      "meta": {
        "escalate_logs": "[{\"department\":\"department A\",\"date_created\":\"2023-11-10T03:54:06.785Z\"}]"
      },
      "agents": ["agent_load_testing_1@keyreply.com"],
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:9f56c9ee-af55-4ff2-bc72-66757fe42903"
      ],
      "status": "resolved",
      "resolved": true,
      "formData": {
        "channel": "Web Chat"
      },
      "RowKey": "clos3235k004jw0bqfjgs0t91",
      "PartitionKey": "localhost",
      "date_created": "2023-11-10T03:53:31.256Z",
      "last_modified": "2023-11-10T03:54:07.327Z",
      "user_id": "9f56c9ee-af55-4ff2-bc72-66757fe42903",
      "sessionId": "a46becd6-b456-4826-9123-7ca5dc413581",
      "startQueueTime": "2023-11-10T03:53:31.257Z",
      "startResolveTime": "2023-11-10T03:53:34.033Z",
      "endResolveTime": "2023-11-10T03:54:07.327Z",
      "endedBy": "agent",
      "department": "00000000-0000-0000-0000-000000000000",
      "provider": "keyreply",
      "waiting_for_assignment": false
    },
    "escalatedLivechat": {
      "RowKey": "clos32v4k005aw0bq0pb0eszo",
      "PartitionKey": "localhost",
      "startQueueTime": "2023-11-10T03:54:07.509Z",
      "startResolveTime": "2023-11-10T03:54:07.509Z",
      "agents": [],
      "date_created": "2023-11-10T03:54:07.509Z",
      "tags": [
        "channel:webchat",
        "PartitionKey:localhost",
        "RowKey:9f56c9ee-af55-4ff2-bc72-66757fe42903"
      ],
      "resolved": false,
      "user_id": "9f56c9ee-af55-4ff2-bc72-66757fe42903",
      "department": "b26a630e-e388-4c64-a415-429d1a97f1ae",
      "sessionId": "a46becd6-b456-4826-9123-7ca5dc413581",
      "waiting_for_assignment": true,
      "status": "pending",
      "formData": {
        "channel": "Web Chat"
      },
      "provider": "keyreply",
      "meta": {
        "escalate_logs": "[{\"department\":\"department A\",\"date_created\":\"2023-11-10T03:54:06.785Z\"}]"
      }
    }
  },
  "sentAt": "2023-11-10T03:54:16.330Z"
}

Errors

The KeyReply API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- The data requested is hidden for administrators only.
404 Not Found -- The specified data could not be found.
405 Method Not Allowed -- You tried to access a data with an invalid method.
429 Too Many Requests -- You're requesting too many data! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.