Skip to content
FacebookYouTubeX (Twitter)

Realtime API

The Realtime API provides programmatic access to ongoing activity in your Pingstreams server.

The Realtime API is implemented using WebSocket technology.

You can use the API to do the following:

  • Display requests data
  • Display agents data
  • Create and display a real-time dashboard
  • Predict or estimate capacity and other derived metrics

The Realtime API allows you to receive events from Pingstreams after you subscribe to one or more topics.

This API is an SSL-only API. You must be a verified user to make API requests. You can authorize against the API using JWT token.

  • /PROJECT_ID/requests - Get the last open requests of a project
  • /PROJECT_ID/requests/REQUEST_ID - Get the requests detail
  • /PROJECT_ID/requests/REQUEST_ID/messages - Get the request messages
  • /PROJECT_ID/project_users/PROJECT_USER_ID - Get the agents info

We only allow a certain number of new connections per minute. The number of new connections to the Realtime API is restricted by REST API rate limits. We also allow a certain number of concurrently running connections to the Realtime API.

We reserve the right to adjust the rate limit for given endpoints in order to provide a high quality of service for all clients. If the rate limit is exceeded, Pingstreams will respond with a body that details the reason for the rate limiter kicking in.

We also limit the total amount of data exchanged through real time APIs. For example the number of Realtime requests exchanged can’t exceed a certain number of items. If this number is exceeded you can always use REST APIs to get additional data or to make more complex queries.

  1. Establish an authenticated WebSocket connection to wss://eu.rtmv3.pingstreams.com/api/.
  2. Subscribe to one or several topics.
  3. Process incoming events.
  4. Unsubscribe to topics.
  • Owner
  • Administrator
  • Agent

Connect to the wss://eu.rtmv3.pingstreams.com/api/ WebSocket endpoint using your JWT token.

var ws = new WebSocket("wss://eu.rtmv3.pingstreams.com/api/?token=YOUR_JWT_TOKEN");

ws.onopen = function () {
  console.log('websocket is connected.');
}

ws.onclose = function () {
  console.log('websocket is closed.');
}

ws.onerror = function () {
  console.log('websocket error ...')
}

Once connection is established, you can send messages to subscribe to individual topics. Refer to Topics for the topic key.

{
  "action": "subscribe",
  "payload": {
    "topic": "/<YOUR_PROJECT_ID_HERE>/requests"
  }
}

To subscribe to a topic you can execute:

ws.send(JSON.stringify(subscriptionMessage));
var subscriptionMessage = {
  "action": "subscribe",
  "payload": {
    "topic": "/5df26badde7e1c001743b63c/requests"
  }
}

ws.send(JSON.stringify(subscriptionMessage));

Once you have subscribed to one or several topics, listen to subsequent messages to start collecting data.

ws.onmessage = function(message) {
  console.log(message);
  try {
    var data = JSON.parse(message.data);
  } catch (e) {
    return console.log('This doesn\'t look like a valid JSON: ', message.data);
  }
  //.... ADD YOUR LOGIC HERE
}

The following are sample messages received after subscribing to requests topic:

{
  "action": "publish",
  "payload": {
    "topic": "/5eb45fbc1f9e1f0012d62207/requests",
    "method": "CREATE",
    "message": [
      {
        "_id": "5eb4fc911f9e1f0012d62248",
        "status": 200,
        "preflight": false,
        "participants": [
          "5eb45fb21f9e1f0012d62201"
        ],
        "request_id": "support-group-1a952f2f-c09a-46be-bc75-11387a95d55f",
        "requester": "5eb45fbc1f9e1f0012d62208",
        "lead": {
          
        },
        "first_text": "hello world",
        "department": "5eb45fbc1f9e1f0012d62209",
        "assigned_at": "2020-05-08T06:30:41.090Z",
        "id_project": "5eb45fbc1f9e1f0012d62207",
        "createdBy": "5eb45fb21f9e1f0012d62201",
        "tags": [
          
        ],
        "notes": [
          
        ],
        "channel": {
          "name": "chat21"
        },
        "createdAt": "2020-05-08T06:30:41.094Z",
        "updatedAt": "2020-05-08T06:31:00.367Z",
        "__v": 0,
        "first_response_at": "2020-05-08T06:30:58.109Z",
        "waiting_time": 17015,
        "id": "5eb4fc911f9e1f0012d62248"
      }
    ]
  }
}

Once you stop processing some data, you can individually unsubscribe from a topic. Events will then stop being pushed on the connection.

{
  "action": "unsubscribe",
  "payload": {
    "topic": "/<YOUR_PROJECT_ID_HERE>/requests"
  }
}

You can find a simple example of the Pingstreams Realtime API here