These are chat archives for ipcortex/FAC-FMC

14th
Jun 2016
Rob Pickering
@rjp44
Jun 14 2016 10:55
Hi folks, how are you getting on this week without Pete. Ben and I are keeping an eye on the issues list from time to time, but if there is anything you specifically need input on then please shout up either here or email and we are happy to help.
Robert Francis
@RobStallion
Jun 14 2016 14:20
Hey guys. Thanks for getting back to us regarding the issues. We are just wondering when Ben will be coming in this week as we would like to go over a few things to do with API and auth that may be slightly easier in person.
Ben Gesoff
@bengesoff
Jun 14 2016 14:20
Whenever you'd like sir!
Tomorrow?
Robert Francis
@RobStallion
Jun 14 2016 14:21
Tomorrow would be great
Ben Gesoff
@bengesoff
Jun 14 2016 14:22
Wonderful, 10am?
Robert Francis
@RobStallion
Jun 14 2016 14:23
Perfect
Thanks
Ben Gesoff
@bengesoff
Jun 14 2016 14:53
Have you tried any API stuff?
Ben Gesoff
@bengesoff
Jun 14 2016 15:16
var request = require("request");

var options = { method: 'POST',
  url: 'https://fac1.ipcortex.net/rest/call/list',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json' },
  body: 
   { type: 'recording',
     scope: { company: 'default' },
     auth: { type: 'auth', key: 'tywfu4765fw74ie6b5fow4387f5bw7346bf5' } },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
Just an example of some node code
Using the request library
Some background: I created a user on the PBX called loginname and gave it Call-Recording download permissions. I then created an API token for that user which you can see in the body above
tywfu4765fw74ie6b5fow4387f5bw7346bf5
If you run that response you should receive:
json { "result": "success", "values": [ { "file": "2016.06.14.16.08.58-1465916938-webrtc674-241.wav", "start": 1465916938, "caller": "webrtc674", "callee": "241", "size": 64698, "duration": 9 } ], "numrows": 1 }
(sorry I tried to JSON format that)
Ben Gesoff
@bengesoff
Jun 14 2016 15:21
Anyway, as you can see, the filename is passed back (2016.06.14.16.08.58-1465916938-webrtc674-241.wav) with the duration (9)
(This is a random call Steve and I made to each other - feel free to listen to it but it'll be very anticlimactic)
If there were more calls, the response would have more objects in the array
Moving on...
Given that filename, we can run:
var request = require("request");

var options = { method: 'POST',
  url: 'https://fac1.ipcortex.net/rest/call/download/recording',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json' },
  body: 
   { type: 'recording',
     scope: 
      { company: 'default',
        file: '2016.06.14.16.08.58-1465916938-webrtc674-241.wav' },
     auth: { type: 'auth', key: 'tywfu4765fw74ie6b5fow4387f5bw7346bf5' } },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
Note here, the same "auth" object is passed
with the API key
The response body here is the binary wav file
Success
For the docs on this
Ben Gesoff
@bengesoff
Jun 14 2016 15:26
Very happy to still come down tomorrow but play with this and see if it answers anything
var http = require("https");

var options = {
  "method": "POST",
  "hostname": "fac1.ipcortex.net",
  "port": null,
  "path": "/rest/call/download/recording",
  "headers": {
    "content-type": "application/json",
    "cache-control": "no-cache"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ type: 'recording',
  scope: 
   { company: 'default',
     file: '2016.06.14.16.08.58-1465916938-webrtc674-241.wav' },
  auth: { type: 'auth', key: 'tywfu4765fw74ie6b5fow4387f5bw7346bf5' } }));
req.end();
If you don't want the request library
PS don't actually try that
Ben Gesoff
@bengesoff
Jun 14 2016 15:32
Change the console.log(body) to something more useful with the binary .wav data
but that's where the data will be :smile:
Ben Gesoff
@bengesoff
Jun 14 2016 16:14
Let me know if you still need me down there
Steve Davies
@davies147
Jun 14 2016 16:22
Just FYI, the "webrtc674" token in the middle of the filename is caused because we did not fully configure Ben's handset before making the test call. It would normally be Ben's extension number in that spot.