workano-js-sdk
v0.5.19
Published
Workano Communications SDK - A modern JavaScript SDK for WebRTC and VoIP integration.
Downloads
52
Maintainers
Readme
Workano JS SDK
Workano JavaScript SDK is a simplified solution for communications.
Website
Installation
npm i workano-js-sdkModules overview
The SDK exposes a friendly facade under workano-js-sdk with these modules:
- Auth: Authentication helpers (login, validateToken, refreshToken, logout, session)
- Phone: WebRTC phone controls (connect, call, accept, hangup, mute, transfer, conference, devices)
- CallLog: Call history, recordings, voicemails, and related events
- User: User management helpers (addUser, getExtensions)
- Contact: Directory sources, favorites, phonebooks, personal contacts
- Chat: Rooms, messages, presence, and chat file transfer
- Config: User call forward options
- Agent: Call-center agent controls and events
- Api: Access the underlying low-level API client
- Websocket: Handy wrappers for common call events
Below are quick-start snippets for the most used modules. Explore src/modules/*/index.ts for full surface.
Auth
Login
import workano from "workano-js-sdk";
const session = await workano.Auth.login({
server: "https://your.workano.host",
username: "[email protected]",
password: "••••••••",
appId: "your-app-id",
tokenExpiration: 3600, // seconds
isMobile: false,
onTokenRefreshed(newSession) {
// Persist updated tokens/session as needed
},
});Validate token
const session = await workano.Auth.validateToken({
server: "https://your.workano.host",
token, // access token
appId: "your-app-id",
tokenExpiration: 3600,
isMobile: false,
onTokenRefreshed(newSession) {
// Called automatically when the SDK refreshes the token
},
});Refresh token explicitly
// When you only have a refresh token and need a new session
const newSession = await workano.Auth.refreshToken(refreshToken);
if (newSession) {
// you are authenticated again
}Get current session
const current = workano.Auth.session();Logout
await workano.Auth.logout();Phone
import workano from "workano-js-sdk";
// Connect once (e.g., on app start)
await workano.Phone.connect({
sipLine?: SipLine | null;
onIncomingCall: (callSession: CallSession) => {};
onCallFailed: (callSession: CallSession) => {};
onCallEnded: (callSession: CallSession) => {};
onCallCanceled: (callSession: CallSession) => {};
onCallAccepted: (callSession: CallSession) => {};
onCallHeld?: (callSession: CallSession) => {};
onCallResumed?: (callSession: CallSession) => {};
onCallRejected?: (callSession: CallSession) => {};
onCallMuted?: (callSession: CallSession) => {};
onCallUnMuted?: (callSession: CallSession) => {};
onAdhocParticipantLeft?: (data: {
callId: string;
conferenceId: string;
}) => {};
onAdhocDeleted?: (conferenceId: string) => {};
onDisconnected?: () => {};
onNetworkStats?: (
callSession: CallSession,
stats: any,
prevStats: any
) => {};
onProgress?: () => {};
onPlayProgressSound?: (data?: any) => {};
onPlayHangupSound?: () => {};
onSignal?: () => {};
onMessage?: () => {};
});
// Place a call
const withVideo = true;
await workano.Phone.call("1001", withVideo);Selected helpers:
- accept/hangup/mute/unmute/hold/resume
- directTransfer(number) and indirectTransfer(number)
- startConference(hostCall, otherCalls)
- toggleRecording(callId, enable)
- sendDTMF(tone, callSession)
- changeAudioDevice/changeAudioInputDevice/changeVideoInputDevice/changeRingDevice
Call logs
const offset = 0;
const limit = 20;
const callLogs = await workano.CallLog.list(offset, limit);Extras:
- CallLog.voicemails()
- CallLog.voicemailUrl(voicemail)
- CallLog.recordingFileUrl(cdrId, recordingUuid)
- CallLog.search({ contactUuid?, query?, pageSize })
- CallLog.onCallLogCreated(listener)
User
Get extensions
const availableNumbers = await workano.User.getExtensions();
// [
// { context: "default", contextLabel: "Default Context", numbers: ["1001", "1002"] },
// { context: "webrtc", contextLabel: "WebRTC Context", numbers: ["2001"] }
// ]Add user
const user = {
subscription_type: 1, // 0: Normal, 1: Integrated Phone System, 2: Meeting, 3: Call Center
firstname: "Jane",
lastname: "Smith",
firstname_english: "Jane",
lastname_english: "Smith",
language: "en_US",
mobile_phone_number: "0987654321",
email: "[email protected]",
password: "securepassword",
lines: [
{ extensions: [{ context: "default", exten: "1004" }] },
],
};
const newUser = await workano.User.addUser(user);Contact
- sources(): list directory sources (workano, conference, phonebook)
- workanoContactsAndPresence(source, params)
- conferenceContacts(source, params?)
- personalContacts(params?)
- phonebookContacts(source, params?)
- addPhonebookContact(phonebookUuid, contact)
- editPhonebookContact(phonebookUuid, contact)
- addContact(newContact), editContact(contact)
- favorites(), markAsFavorite(sourceName, sourceId), removeFavorite(sourceName, sourceId)
Chat
- updateStatus(state, status)
- rooms(), messages(opts), roomMessages(roomUuid, opts?)
- createRoom(name, targetUserUuid, workano_uuid)
- sendMessage(alias, roomUuid, text)
- uploadFile(roomUuid, file), download(roomUuid, fileUuid)
- onNewRoom(listener), onNewMessage(listener), onPresenceChanged(listener), onLineStateChanged(listener), off()
Config
- updateForwardOption(userUuid, key, destination, enabled)
Agent
- getStatus(), loginWithLineId(lineId), logout()
- pause(reason?), resume()
- onStatusUpdate(listener), onPaused(listener), onUnpaused(listener), off()
Api client
const apiClient = workano.Api.client();Websocket helpers
- onCallAnswered(listener, forAll?)
- onCallEnded(listener, forAll?)
- onCallCreated(listener, forAll?)
- onCallUpdated(listener, forAll?)
- off()
Support
For questions or support, contact: [email protected]
