Skip to content
Wazo's JavaScript Software Development Kit.
JavaScript
Branch: master
Clone or download
Latest commit 690b4c8 Sep 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
flow-typed/npm Add domain models Sep 25, 2018
src Avoid to change for the same device id Sep 12, 2019
.babelrc Fix test Jul 8, 2019
.eslintignore Add Travis YAML config Jun 22, 2018
.eslintrc Move CTIPhone domain Jul 22, 2019
.flowconfig Fix test Jul 8, 2019
.gitignore Bundle CJS files Jun 20, 2019
.hooks4git.ini add basic hooks4git config to run test and format before push Apr 18, 2019
.lintstagedrc
.npmignore get rid of .babelrc from npm package Nov 14, 2018
.travis.yml
LICENSE Initial commit Jun 4, 2018
README-dev.md add section for git hook management Apr 23, 2019
README.md Update README.md Aug 19, 2019
config.js Handle JWT Feb 20, 2019
package.json 0.23.20 Sep 12, 2019
rollup.config.js
webpack.config.js Move merge session into sdk Jan 9, 2019
yarn.lock

README.md

Wazo's JavaScript Software Development Kit

npm version Greenkeeper badge

The Wazo JavaScript Software Development Kit is an API wrapper making it easy for you to communicate with your Wazo server. It allows you to add Wazo functionalities to any JavaScript application you are developing.

Usage

Install / Add

You may install the Wazo JavaScript Software Development Kit to your project one of the following ways:

  • npm install @wazo/sdk
  • yarn add @wazo/sdk

Content Delivery Networks

Alternatively, you may load the Wazo SDK from a CDN. Use one of the following Content Delivery Networks:

UNPKG

<script src="https://unpkg.com/@wazo/sdk/dist/wazo-sdk.js"></script>

jsDelivr

<script src="https://cdn.jsdelivr.net/npm/@wazo/sdk"></script>

Require / Import

Depending on your preference, you may require or add the Wazo SDK to your own client application one of the following ways:

  • const { WazoApiClient } = require('@wazo/sdk');
  • import { WazoApiClient } from '@wazo/sdk';

Depending on your environment you can import:

  • @wazo/sdk/esm: compatible with (most) browsers only.
  • @wazo/sdk/lib: runnable on node env.

Init

const client = new WazoApiClient({
  server: 'demo.wazo.community', // required string
  agent: null // http(s).Agent instance, allows custom proxy, unsecured https, certificate etc.
});

Log In

client.auth.logIn({
  expiration, // optional integer. Session life in number of seconds. If omitted, defaults to 3600 (an hour).
  username, // required string
  password, // required string
  backend, // optional string. If omitted, defaults to wazo_user
  mobile, // optional boolean. If omitted, defaults to false: tells if the current user uses a mobile application
}).then(/* undefined if login failed, or : */{
  metadata: {
    username,
    uuid_tenant_uuid,
    xivo_user_uuid,
    groups,
    xivo_uuid,
    tenants: [{ uuid }],
    auth_id
  },
  token, // should be used for other request
  acls,
  utc_expires_at,
  xivo_uuid,
  issued_at,
  utc_issued_at,
  auth_id,
  expires_at,
  xivo_user_uuid
});
// or
const result = await client.auth.login(/* ... */);

Log Out

client.auth.logOut(token).then(/* ... */);
// or
await client.auth.logOut(token);

Check token

client.auth.checkToken(token).then(valid);
// or
const valid = await client.auth.checkToken(token);

Other auth methods

client.auth.listTenants(token);
client.auth.createTenant(token, name);
client.auth.deleteTenant(token, uuid);
client.auth.createUser(token, username, password, firstname, lastname);
client.auth.addUserEmail(token, userUuid, email, main);
client.auth.addUserPolicy(token, userUuid, policyUuid);
client.auth.deleteUser(token);
client.auth.listUsers(token);
client.auth.listGroups(token);
client.auth.createPolicy(token, name);
client.auth.listPolicies(token);

Application

client.application.calls(token, applicationUuid); // list calls
client.application.hangupCall(token, applicationUuid, callId); // hangup a call
client.application.answerCall(token, applicationUuid, callId, context, exten, autoanswer);  // answer a call
client.application.listNodes(token, applicationUuid); // list nodes
client.application.listCallsNodes(token, applicationUuid, nodeUuid); // list calls in a node
client.application.removeCallNodes(token, applicationUuid, nodeUuid, callId); // remove call from node (no hangup)
client.application.addCallNodes(token, applicationUuid, nodeUuid, callId); // add call in a node
client.application.playCall(token, applicationUuid, callId, language, uri); // play a sound into a call

Calld

client.calld.getConferenceParticipantsAsUser(token, conferenceId); // List participants of a conference the user is part of

Confd

client.confd.listUsers(token);
client.confd.getUser(token, userUuid);
client.confd.getUserLineSip(token, userUuid, lineId);
client.confd.listApplications(token);

Dird

client.dird.search(token, context, term);
client.dird.listPersonalContacts(token);
client.dird.addContact(token, newContact);
client.dird.editContact(token, contact);
client.dird.deleteContact(token, contactUuid);
client.dird.listFavorites(token, context);
client.dird.markAsFavorite(token, source, sourceId);
client.dird.removeFavorite(token, source, sourceId);

Call Logd

client.callLogd.search(token, search, limit);
client.callLogd.listCallLogs(token, offset, limit);
client.callLogd.listCallLogsFromDate(token, from, number);

Calld

Please note, ctidNg endpoint is obsolete but continue to work with old version. Please update your code.

client.calld.answerSwitchboardQueuedCall(token, switchboardUuid, callId);
client.calld.answerSwitchboardHeldCall(token switchboardUuid, callId);
client.calld.cancelCall(token, callId);
client.calld.deleteVoicemail(token, voicemailId);
client.calld.fetchSwitchboardHeldCalls(token, switchboardUuid);
client.calld.fetchSwitchboardQueuedCalls(token, switchboardUuid);
client.calld.getConferenceParticipantsAsUser(token, conferenceId);
client.calld.getPresence(token, contactUuid}; //deprecated use chatd in ctidNg, don't work with calld
client.calld.getStatus(token, lineUuid); //deprecated use chatd in ctidNg, don't work with calld
client.calld.holdSwitchboardCall(token, switchboardUuid, callId);
client.calld.listCalls(token);
client.calld.listMessages(token, participantUuid, limit);
client.calld.listVoicemails(token);
client.calld.makeCall(token, extension, fromMobile, lineId);
client.calld.sendFax(token, extension, fax, callerId);
client.calld.sendMessage(token, alias, msg, toUserId);
client.calld.relocateCall(token, callId, destination, lineId);
client.calld.updatePresence(token, presence);

Accessd

client.accessd.listSubscriptions(token);
client.accessd.createSubscription(token, { productSku, name, startDate, contractDate, autoRenew, term });
client.accessd.getSubscription(token, uuid);
client.accessd.listAuthorizations(token);
client.accessd.getAuthorization(token, uuid);

WebRTCPhone

import { WazoWebRTCClient } from '@wazo/sdk';

const session = await client.auth.logIn({ ... });

const phone = new WazoWebRTCClient({
  displayName: 'From WEB',
  host: 'demo.wazo.community',
  media: {
    audio: boolean,
    video: boolean | document.getElementById('video'), // pointing to a `<video id="video" />` element
    localVideo: boolean | document.getElementById('video'), // pointing to a `<video id="video" />` element
  }
}, session);

// eventName can be on the of events : 
// - transport: `connected`, `disconnected`, `transportError`, `message`, `closed`, `keepAliveDebounceTimeout`
// - webrtc: `registered`, `unregistered`, `registrationFailed`, `invite`, `inviteSent`, `transportCreated`, `newTransaction`, `transactionDestroyed`, `notify`, `outOfDialogReferRequested`, `message`.
phone.on('invite', (sipSession: SIP.sessionDescriptionHandler, hasVideo: boolean, shouldAutoAnswer: boolean) => {
  this.currentSipSession = sipSession;
  // ...
});

phone.call('1234');

Calling a number

phone.call(number: string);

Be notified to a phone call

phone.on('invite', (sipSession: SIP.sessionDescriptionHandler) => {
  this.currentSipSession = sipSession;
});

Answering a call

phone.answer(sipSession: SIP.sessionDescriptionHandler);

Hangup a call

phone.hangup(sipSession: SIP.sessionDescriptionHandler);

Rejecting a call

phone.reject(sipSession: SIP.sessionDescriptionHandler);

Muting a call

phone.mute(sipSession: SIP.sessionDescriptionHandler);

Umuting a call

phone.unmute(sipSession: SIP.sessionDescriptionHandler);

Holding a call

phone.hold(sipSession: SIP.sessionDescriptionHandler);

Unholding a call

phone.unhold(sipSession: SIP.sessionDescriptionHandler);

Transferring a call

phone.transfert(sipSession: SIP.sessionDescriptionHandler, target: string);

Sending a DTMF tone

phone.sendDTMF(sipSession: SIP.sessionDescriptionHandler, tone: string);

Sending a message

phone.message(message: string, destination: string);

Closing the RTC connection

phone.close();

Merging sessions in one conference

phone.merge(sessions: Array<SIP.InviteClientContext>);

Add a session to a conference

phone.addToMerge(sipSession: SIP.InviteClientContext);

Remove a session from a conference

phone.removeFromMerge(sipSession: SIP.InviteClientContext, shouldHold: boolean);
// shouldHold indicate if the session should be held after removed from session

Unmerge a sessions from a conference

phone.unmerge(sipSessions: Array<SIP.InviteClientContext>)

Wazo Websocket

import { WazoWebSocketClient } from '@wazo/sdk';

const ws = new WazoWebSocket({
  host, // wazo websocket host
  token, // valid Wazo token
});

// eventName can be on the of events here: http://documentation.wazo.community/en/stable/api_sdk/websocket.html
ws.on('eventName', (data: mixed) => {
});

ws.connect();

Closing the socket

ws.close();
You can’t perform that action at this time.