user5593728
user5593728

Reputation:

How to get a Twilio worker statistics based on the minutes in nodejs

As mentioned in the Twilio document (https://www.twilio.com/docs/api/taskrouter/worker-statistics) that specify the parameters Minutes, StartDate, EndDate to retrieve the worker statistics but i tried in many ways to fetch based on 240 minutes (4 hours),its giving default 15 minutes worker statistics every time on request and there is no proper document on nodeJS.

please find the code for nodeJs below

client.workspace.workers(workerSid).statistics.get({}, function(err, responseData) {
    if(!err) {
        console.log(responseData.cumulative.reservations_accepted);
    }
});

Someone help to resolve this issue, Thanks in advance.

Upvotes: 1

Views: 163

Answers (1)

philnash
philnash

Reputation: 73055

Twilio developer evangelist here.

As smarx has said, it does look like you're using the version 2 syntax for this. I recommend that you use the version 3 Twilio module for Node.

When you are using that version, then you can get the statistics for a worker over the last 4 hours with the following code:

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken  = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
const workspaceSid = 'WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const workerSid = 'WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const client = require('twilio')(accountSid, authToken);

client.taskrouter.v1
  .workspaces(workspaceSid)
  .workers(workerSid)
  .statistics()
  .fetch({ minutes: 240 })
  .then((responseData) => {
     console.log(responseData);
   });

Note, you pass the minutes parameter to fetch.

Let me know if this helps at all.

Upvotes: 1

Related Questions