Wazo's JavaScript Software Development Kit
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',
agent: null
clientId: null,
});
Log In
client.auth.logIn({
expiration,
username,
password,
backend,
mobile,
}).then({
metadata: {
username,
uuid_tenant_uuid,
xivo_user_uuid,
groups,
xivo_uuid,
tenants: [{ uuid }],
auth_id
},
acls,
utc_expires_at,
xivo_uuid,
issued_at,
utc_issued_at,
auth_id,
expires_at,
xivo_user_uuid
});
const { refreshToken, ...result } = await client.auth.login();
Set token (and refresh token)
client.setToken(token);
client.setRefreshToken(refreshToken);
Add an event when the token is refreshed
client.setOnRefreshToken((newToken) => {
});
Log Out
client.auth.logOut(token).then();
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();
client.auth.createTenant(name);
client.auth.deleteTenant(uuid);
client.auth.createUser(username, password, firstname, lastname);
client.auth.addUserEmail(userUuid, email, main);
client.auth.addUserPolicy(userUuid, policyUuid);
client.auth.deleteUser();
client.auth.listUsers();
client.auth.listGroups();
client.auth.createPolicy(name);
client.auth.listPolicies();
Application
client.application.calls(applicationUuid);
client.application.hangupCall(applicationUuid, callId);
client.application.answerCall(applicationUuid, callId, context, exten, autoanswer);
client.application.listNodes(applicationUuid);
client.application.listCallsNodes(applicationUuid, nodeUuid);
client.application.removeCallNodes(applicationUuid, nodeUuid, callId);
client.application.addCallNodes(applicationUuid, nodeUuid, callId);
client.application.playCall(applicationUuid, callId, language, uri);
Calld
client.calld.getConferenceParticipantsAsUser(conferenceId);
Confd
client.confd.listUsers();
client.confd.getUser(userUuid);
client.confd.getUserLineSip(userUuid, lineId);
client.confd.listApplications();
Dird
client.dird.search(context, term);
client.dird.listPersonalContacts();
client.dird.addContact(newContact);
client.dird.editContact(contact);
client.dird.deleteContact(contactUuid);
client.dird.listFavorites(context);
client.dird.markAsFavorite(source, sourceId);
client.dird.removeFavorite(source, sourceId);
Call Logd
client.callLogd.search(search, limit);
client.callLogd.listCallLogs(offset, limit);
client.callLogd.listCallLogsFromDate(from, number);
Calld
Please note, ctidNg endpoint is obsolete but continue to work with old version. Please update your code.
client.calld.answerSwitchboardQueuedCall(switchboardUuid, callId);
client.calld.answerSwitchboardHeldCall(switchboardUuid, callId);
client.calld.cancelCall(callId);
client.calld.deleteVoicemail(voicemailId);
client.calld.fetchSwitchboardHeldCalls(switchboardUuid);
client.calld.fetchSwitchboardQueuedCalls(switchboardUuid);
client.calld.getConferenceParticipantsAsUser(conferenceId);
client.calld.getPresence(contactUuid);
client.calld.getStatus(lineUuid);
client.calld.holdSwitchboardCall(switchboardUuid, callId);
client.calld.listCalls();
client.calld.listMessages(participantUuid, limit);
client.calld.listVoicemails();
client.calld.makeCall(extension, fromMobile, lineId);
client.calld.sendFax(extension, fax, callerId);
client.calld.sendMessage(alias, msg, toUserId);
client.calld.relocateCall(callId, destination, lineId);
client.calld.updatePresence(presence);
Accessd
client.accessd.listSubscriptions();
client.accessd.createSubscription({ productSku, name, startDate, contractDate, autoRenew, term });
client.accessd.getSubscription(uuid);
client.accessd.listAuthorizations();
client.accessd.getAuthorization(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'),
localVideo: boolean | document.getElementById('video'),
}
}, session);
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);
Unmerge a sessions from a conference
phone.unmerge(sipSessions: Array<SIP.InviteClientContext>)
Wazo Websocket
import { WazoWebSocketClient } from '@wazo/sdk';
const ws = new WazoWebSocket({
host,
});
ws.on('eventName', (data: mixed) => {
});
ws.connect();
Closing the socket
ws.close();