Have ideas to improve npm?Join in the discussion! »

    @vonage/vbc-web-sdk
    TypeScript icon, indicating that this package has built-in type declarations

    1.17.0 • Public • Published

    VBC Web SDK

    Client side SDK for web applications hosted in Vonage Business Cloud

    Installation

    Use npm to install.

    npm install @vonage/vbc-web-sdk

    Usage Example

    import VBCWebSDK from 'vbc-web-sdk';
    vbc = new VBCWebSDK();
    const token = vbc.initialize();
    // do some verification at your end...
    verifyUser(token);
    vbc.ready();

    Services

    All the services can accept an options object with the following fields:

    • requestTimeout - to set a request timeout. default is set to 10 seconds.

    initialize

    Creates a connection with VBC. Parameters: options returns: -- extensionToken - a string that is used for user verification in the hosted app. -- vbcContext - an object describing the context in which the app was accessed inside VBC. (relevant only for popup for now)

    vbc = new VBCWebSDK();
    token = vbc.initialize(options);

    ready

    Let VBC know the app is ready to be displayed. Parameters: options

    vbc.ready(options);

    error

    In case something went wrong and the app is not ready for user interaction, the method reports an error to VBC. Parameters: options -- error - TBD

    vbc.error(error, options);

    terminate

    Let VBC know the app is being terminated. Parameters: options

    vbc.terminate(options);

    contextInvalid

    Let VBC know that the context sent from it is invalid for the app. Parameters: options

    vbc.contextInvalid(options);

    getContacts

    Request the contacts of the user. Parameters: options returns: -- contacts - an array of contact objects.

    contacs = vbc.getContacts(options);

    contact:

    {
    	"addresses": [],
    	"cuid": "123456789e123456789",
    	"display": { "tel": "", "ext": "x0000", "status": "available", "isContactable": true, "description": "always on time" },
    	"displayName": "John Smith",
    	"firstName": "John",
    	"isFavorite": false,
    	"isOffNet": false,
    	"labels": ["CAB"],
    	"lastName": "Smith",
    	"mailingAddresses": "some  address",
    	"organization": "JM  corps",
    	"props": null,
    	"revision": 1234567890,
    	"title": "JM  corps  CEO"
    }

    makeCall

    Request VBC to make a call to some number. Parameters: toNumber, options returns: TBD

    vbc.makeCall(toNumber, options);

    getUserInfo

    Request VBC to get user information. Parameters: options returns: --userInfo - an array of user information.

    vbc.getUserInfo(options);

    sendMessage

    Request VBC to send a message. Parameters:

    • messageBody - the message to be sent.
    • contactNumber - the number to send the message to.
    • contactId - in case the number is invalid, allows VBC to the contactId default number.
    • options
    vbc.sendMessage(messageBody, contactNumber, contactId, options);

    openPopup

    Request VBC to open a popup window inside vbc. Parameters:

    • url - the url to embed in the popup
    • title - title of the modal
    • options
    vbc.openPopup(url, title, options);

    hangupCall

    Requests VBC hang up an ongoing call. Parameters: callId, options

    vbc.hangupCall(callId, options);

    muteCall

    Requests VBC mute/unmute an ongoing call. Parameters: callId, options

    vbc.muteCall(callId, options);

    sendDTMF

    Requests VBC to dial a digit in an ongoing call. Parameters: callId, digit, options

    vbc.sendDTMF(callId, digit, options);

    manageCalls

    Requests VBC to manage calls. Parameters: parameters, options Using the manageCalls without any parameters will toggle the app state from false to true and vice-versa. Using the parameters, the app can customize the VBC behaviour of managing calls. Each of the following parameters has a default value, that is set if the parameter was not explicitly stated. Default values will only be set when toggling 'manage-calls' from false to true and will not take effect if 'manage-calls' was already active. Therefore you can partially update the 'manage-calls' settings without worrying the default values take effect.

    1. manageCalls - boolean - Turn on or off the 'manage-calls' state on VBC. When true, VBC will set all action parameters into it's state. When set to false, non of the parameters take effect, and all previous values are removed from VBC's state.
    2. playIncomingCallSounds - boolean (default = false) - this parameter determines whether VBC plays the ringing sound for incoming calls or not. Using this parameter you may choose if you want your own app to manage ringing states and play sounds or keep the VBC default behavior.
    3. showIncomingCallScreen - boolean (default = false) - this parameter determines whether VBC shows the incoming call screen when a call rings your softphone. Using this parameter you may choose if you want your own app to show the incoming call indication or not.
    4. showIncomingCallNotification - boolean (default = false) - Whether VBC shows the native notification for incoming calls or not.
    5. showOngoingCallScreen - boolean (default = false) - Whether VBC shows the ongoing call screen. You may use this option to display the status of the ongoing calls on your app instead.
    6. suppressOutboundCalls - boolean (default = false) - When set to true, VBC will not initiate outgoing calls, instead it will send the 'initiate-click-to-call' event. You may use this event to initiate an outbound call from you app instead of VBC.
    7. includeVBCExtensionCalls - boolean (default = true) - When set true, when making an outbound call to an onNet number, VBC will ignore the manage calls settings and the call flow would be as if the manageCalls key was set to false.
    vbc.manageCalls(parameters, options);

    Parameters example:

    {
    	"type": "manage-calls",
    	"parameters": {
    		"manageCalls": true,
    		"playIncomingCallSounds": true,
    		"showIncomingCallScreen": false,
    		"showIncomingCallNotification": false,
    		"showOngoingCallScreen": false,
    		"suppressOutboundCalls": false,
    		"includeVBCExtensionCalls": false
    	}
    }

    Important: When calling emergency numbers - VBC will ignore the manage-calls parameters and act as if the manageCalls key is false.

    registerEvent

    Request VBC to register to an event. Parameters:

    • eventName - the event to be registered to.
    • callBack - function of the application which will be executed when the event happens.
    vbc.registerEvent(eventName, callBack);

    sendCustomAction

    Ask VBC to execute an action (which the application has permissions to).. Parameters:

    • action - an action object to send to VBC
    vbc.sendCustomAction(action);

    Parameters example (asking VBC to execute an action type 'dispatch-action', which changes the value of openSideView to true)

    {
    	"isPrivileged": true,
    	"type": "dispatch-action",
    	"parameters": {
    		"actionId": "openSideView",
    		"isRoot": true,
    		"context": {
    			"value": true
    		}
    	}
    }

    downloadFile

    Send a file to be downloaded, VBC can control how to manage the file downloads. Could have different implementation for Electron and Browser.

    Parameters:

    • url - file's url to download.
    • name - the name of the file to be displayed.
    • type - enum of DOWNLOAD_FILE_TYPES, default is general, values: { general:0, audio:1, video:2, image:3 }
    • thumbnail - optional thumbnail to be displayed for VBC
    vbc.downloadFile(url, name, type, thumbnail, options);

    Contributing

    Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

    Tests

    Unit tests can be run simply by executing:

    npm run test

    License

    MIT

    Keywords

    none

    Install

    npm i @vonage/vbc-web-sdk

    DownloadsWeekly Downloads

    221

    Version

    1.17.0

    License

    MIT

    Unpacked Size

    804 kB

    Total Files

    28

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar