title: Using WebSockets to monitor calls on Asterisk 13
body: <p>I've recently upgraded our PBX to Asterisk 13, in the hope that the new REST API and WebSockets support would solve some problems we were having with tracking calls via the AMI. </p>
  
  <p>We're building a C# application that will sit in the Windows tool tray and bring up information based on caller ID by querying our CRM whenever a user makes or receives a call.</p>
  
  <p>Can someone clarify if it's possible via WS to subscribe to a WS channel that reports all (or even just extension specific) events taking place on the PBX?</p>
  
  <p>In terms of progress made so far, I've used Swagger to explore the ARI, and the channel information given back via the channel endpoint (e.g. <code>http://10.0.0.1:8088/ari/channels?api_key=admin:secret</code>) looks perfect:</p>
  
  <pre><code>[
    {
      "id": "1466860766.240522",
      "name": "PJSIP/905-00000c74",
      "state": "Ring",
      "caller": {
        "name": "",
        "number": "020xxx"
      },
      "connected": {
        "name": "CID:020xxx",
        "number": "07xxx"
      },
      "accountcode": "",
      "dialplan": {
        "context": "macro-dialout-trunk",
        "exten": "s",
        "priority": 22
      },
      "creationtime": "2016-06-25T14:19:26.040+0100",
      "language": "en"
    },
    {
      "id": "1466860766.240524",
      "name": "SIP/siptrunk-000003fc",
      "state": "Down",
      "caller": {
        "name": "CID:02033554047",
        "number": "07xxx"
      },
      "connected": {
        "name": "",
        "number": "020xxx"
      },
      "accountcode": "",
      "dialplan": {
        "context": "ext-did",
        "exten": "07xxx",
        "priority": 1
      },
      "creationtime": "2016-06-25T14:19:26.264+0100",
      "language": "en"
    }
  ]
  </code></pre>
  
  <p>That channel information gives us everything we need in a concise, easy to digest format - PJSIP channel (i.e. the extension), state, outgoing trunk CID, and outbound number being dialled.</p>
  
  <p>However, the <code>/events</code> endpoint as far as I can see depends on you creating an 'application' within Asterisk (from what I can gather like a conference or such?) - and despite two days of trying various things using wscat and reading documentation I can't see any way whereby you can subscribe to a WS channel that will give you all events back similar to the JSON above.</p>
  
  <p>Am I misunderstanding the intentions behind WS support with Asterisk 13? Is it not meant for this purpose? Is there a better way to achieve my aim without polling <code>/channels</code>? Any help/pointers appreciated.</p>