Pub/sub – DEPRECATED

DEPRECATED

By subscribing to various Faye channels it is possible to get (near) realtime updates.

Authentication

We recommend using one of the official Faye clients when connecting. It takes care of a lot of the brunt WebSocket connections work you’d otherwise have to do.

You can get a client from here: https://faye.jcoglan.com/.

Once you have the client, you must get an employee access token as described in the Authentication guide.

You should now be able to connect as shown in the example code below. This code connects to our https://pubsub.firmafon.dk/faye endpoint.

It authenticates by always sending along the employee access_token on outgoing messages.

Then it subscribes to the company’s presence and call2 channels to get messages when employees become busy or take a call respectively. Try calling someone in your company or setting yourself on do not disturb to see the events live.

You can read more about those channels below.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Relatel Live Example</title>

  <style>
    section {
      display: inline-block;
      max-width: 500px;
      vertical-align: top;
      word-break: break-word;
    }
  </style>

  <script>
    // Embed the Faye browser client code from http://faye.jcoglan.com/ here.
  </script>
  <script>
    // Your info here. The employee must be part of the company.
    var COMPANY_ID = 1234; // Find your `company_id` via the employee endpoint: https://app.relatel.dk/api/v2/employee.json
    var EMPLOYEE_ACCESS_TOKEN = 'secret'; // See our authentication guide for info on where to get this.

    document.addEventListener("DOMContentLoaded", function () {
      var client = new Faye.Client('https://pubsub.firmafon.dk/faye');
      Faye.logger = window.console; // Get details about subscribing, unsubscribing etc.

      // Add an extension to always send along the `access_token` as well as an app reference
      // to your app name.
      client.addExtension({
        outgoing: function (message, callback) {
          message.ext = { app: 'relatel.live.example', access_token: EMPLOYEE_ACCESS_TOKEN };
          callback(message);
        }
      });

      // Presence shows when employees and employee groups within a company are available or busy.
      client.subscribe('/presence/company/' + COMPANY_ID, function (message) {
        var element = document.createElement('p');
        element.innerHTML = JSON.stringify(message);
        document.getElementById('presence').appendChild(element);
      });

      // Get call2 events about new calls coming in or an existing one is hung up for instance.
      client.subscribe('/call2/company/' + COMPANY_ID, function (message) {
        var element = document.createElement('p');
        element.innerHTML = JSON.stringify(message);
        document.getElementById('calls').appendChild(element);
      });
    });
  </script>
</head>
<body>
  <section id="calls"></section>
  <section id="presence"></section>
</body>
</html>

Available Channels

You can subscribe to these channels and get updates whenever a new message is posted:

Name Description
/presence/company/:company_id All presence events within the given company. Any employee in the company can subscribe.
/call2/company/:company_id All call events for receptions within the given company. Any employee in the company can subscribe.
/call2/employee/:employee_id All call events for the employee within the given company. Any employee in the company can subscribe.

Message Events

When you have subscribed to a channel, Relatel sends you messages when something new happens on that channel. These are the kinds of messages you can receive.

  1. Presence events
  2. Call events