Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Simple CTI

SimpleCTI is an example class that provides a heavily sanitised interface to the IPCortex API which abstracts away everything that isn't needed for basic inbound call processing or click to dial.

It allows a web developer to make one Javascript call which will initialise the API and register callbacks that will fire whenever a significant call event (e.g. call ringing, answered or hung-up) occurs on the phone of the authenticated user. It also provides Javascript calls to dial, answer or hang-up calls on behalf of the user, and works like this...

Step 1

Include both the SimpleCTI.js class and the normal IPCortex wrapper:

<!DOCTYPE HTML><html><head><scriptsrc="simpleCTI.js" type="text/javascript"></script><!-- *** Substitute your appliance domain name below *** --><scriptsrc="https://pabx.phone.voipcortex.co.uk/api/wrapper.whtm" type="text/javascript"></script>

Step 2

Create an instance by calling the Constructor with a PBX username, password, and set of callback functions that you want to have invoked when something happens:

<script>// *** Substitute a real username and password below ***varCTI=newSimpleCTI("user1","password",statusCB,eventCB,eventCB,eventCB);// Or use this form instead for pop-out user auth on 6.1+ software// var CTI = new SimpleCTI([statusCB, eventCB, eventCB, eventCB]);// Status callback - just insert anything we get into the <h2> in the bodyfunctionstatusCB(status,code,reason){varstatus=document.getElementById('status');status.innerHTML=reason+" ("+code+")";}// Call event callback - we use the same callback for all three event types// and key off the first state parameter to work out what to do.functioneventCB(state,number,party,call,line){varcallstatus=document.getElementById('callstatus');varstatuspanel=document.getElementById('statuspanel');console.log('got '+state+' event to number '+number+' we are the '+party);switch(state){case'ring':
description='Ringing: ';break;case'up':
description='Answered: ';break;case'dead':
description='Nothing Doing, last call was: ';break;}if(party=='callee')description+=number+' calling us';elsedescription+='calling '+number;if(state!='dead')description+=' <a href="#" onClick="CTI.hangup(\''+call.attr.id+'\')">hangup</a>';if(state=='ring'&&party=='callee')description+=' <a href="#" onClick="CTI.answer(\''+call.attr.id+'\')">answer</a>';callstatus.innerHTML=description;statuspanel.src='http://www.google.com/custom?q='+number;}</script>

Step 3

Wait for status and call event updates via your callbacks!

<title>Simple CTI Test page</title></head><body><h1>Simple CTI Test</h1><p>This page displays the status and a google lookup of the phone number for any inbound or outbound call</p><h2id="status">API not initialised</h1><inputid="thenumber" type="text"></input><buttononClick="CTI.dial(document.getElementById('thenumber').value);">Dial me</button><h1id="callstatus">Nothing doing</h1><iframeid="statuspanel" height="400" width="100%"></iframe></body></html>

Class Documentation

SimpleCTI

Really simple example of a CTI class that allows client side Javascript to interact with a PBX

Kind: global class

new SimpleCTI(callbacks)

Creates a new SimpleCTI class using pop-out javascript auth. Plants callbacks that will be used to signal API startup completion and called when a call status changes on a line.

ParamTypeDescription
callbacksArrayArray of functions (status, ring, up, dead as below), uses new form of pop-out auth (requires PBX firmware v6.1+)

new SimpleCTI(username, password, statusCB, [ringCB], [upCB], [deadCB])

Old usage (PBX v6.0 and below)

ParamTypeDescription
usernameStringA valid PBX username for a user who owns a phone
passwordStringUsers password
statusCBstatusCallbackto call on error or successful API initialisation - old style usage only, not used if first param is an array of functions
[ringCB]eventCallbackto call when a line on users phone rings - old style usage only, not used if first param is an array of functions
[upCB]eventCallbackto call when a line on users phone is answered - old style usage only, not used if first param is an array of functions
[deadCB]eventCallbackto call when a line on users phone is hung up - old style usage only, not used if first param is an array of functions

SimpleCTI.dial(number, [line])

Dial a number, optionally specify line

Kind: static method of SimpleCTI

ParamTypeDefaultDescription
numbernumberto dial
[line]number0line index (zero based)

SimpleCTI.hangup(id)

Hangup a call

Kind: static method of SimpleCTI

ParamTypeDescription
idStringID of call to hangup

SimpleCTI.answer(id)

Answer a call

Kind: static method of SimpleCTI

ParamTypeDescription
idStringID of call to answer

SimpleCTI~statusCallback

Status (initialisation) event callback

Kind: inner property of SimpleCTI

ParamTypeDescription
okBooleantrue or false: true: API successfully started false: error condition
codenumbernumeric API error code (status == false only)
textStringtextual explanation suitable for user display

SimpleCTI~eventCallback

Call event callback

Kind: inner property of SimpleCTI

ParamTypeDescription
stateStringone of 'ring', 'up', 'dead' - new state of call
numberStringThe Caller ID of the other party. Caution: may not be numeric in all cases
partyString'caller' or 'callee' - defines which role we are
callObjectRaw underlying call object
lineObjectRaw underlying line object

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages