Javascript CLI library
Introduction to Daktela JS Integrations
Daktela can be integrated with browser-based application where you can control users from simple operations such as logging in or out, to more complex ones like working with calls, sending SMSes or creating tickets. The integrations uses our API that supports JSONP. Alternatively, we can allow JSON for Cross-Origin Resource Sharing. API authorisation is achieved using an accessToken unique for each user. It can be sent as a value in the request, in a cookie or in the header under the X-Auth-Token name. You can call these actions manually or use our CLI library which is currently in experimental stages.
How to Log a User in to a Queue
Queues are used to manage individual channels such as web chat, calls, SMSes etc. A user needs to be logged in to an outgoing queue to make a call. For more info, see our API documentation.
// Log in user to queue 2000 with penalty 0
$.post("https://<pbx_name>.daktela.com/api/v6/usersSession.json", {
accessToken: "<accessToken>",
queues: [
{login: true, name: 2000, penalty: 0}
]
});
// Init CLI
var cli = new daktelaCLI();
cli.init({
host: "https://<pbx_name>.daktela.com",
accessToken: "<accessToken>"
});
// Called with CLI
cli.userSessions.queue(2000, true, 0);
How to Make a Call for a User
To create a call, you will need the accessToken of a user who is allowed to make calls or has rights to another user that is allowed to make calls (if you want to create a call for another user). For more info, see our API documentation.
// Create call on number 123456789 in queue 2000 for acl user
$.post("https://<pbx_name>.daktela.com/api/v6/activities.json", {
accessToken: "<accessToken>",
number: "123456789",
type: "CALL",
queue: 2000
});
// Called with CLI
cli.activities.call.dial({
number: "123456789",
queue: 2000
});
How to Get Current User State
If you need your app to display the user's current state in Daktela, ie. if they have an open call, if they are on a pause or what queues they are logged in to, you can use a one-off query or HTTP long polling. For long polling, you will first need to send the hash parameter. After you receive the response, enter the value into the hash – this is used to detect changes. For more info, see our API documentation.
// Get dynamic data for acl user
$.get("https://<pbx_name>.daktela.com/api/v6/appPullData.json?accessToken=<accessToken>&hash=<hash>").done(function (response) {
// In response you get structured dynamic data for acl user
});
// Called with CLI
cli.appPullData("<hash>", function (response) {
// Success response
});
Simple Example Integration
This example shows how to create a simple application which can log a user in and control their pauses:
Manual example – index 2.html
Example using CLI – index_cli.html