Skip to content

ipcortex/SimpleCTI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

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>
    <script src="simpleCTI.js" type="text/javascript"></script>
    <!-- *** Substitute your appliance domain name below *** -->
    <script src="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 ***
    var CTI = new SimpleCTI("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 body
    function statusCB(status, code, reason){
        var status = 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.
    function eventCB(state, number, party, call, line){
        var callstatus = document.getElementById('callstatus');
        var statuspanel = 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';
        else
                description += '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>

        <h2 id="status">API not initialised</h1>

        <input id="thenumber" type="text"></input>
        <button onClick="CTI.dial(document.getElementById('thenumber').value);">Dial me</button>

        <h1 id="callstatus">Nothing doing</h1>
        <iframe id="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.

Param Type Description
callbacks Array Array 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)

Param Type Description
username String A valid PBX username for a user who owns a phone
password String Users password
statusCB statusCallback to call on error or successful API initialisation - old style usage only, not used if first param is an array of functions
[ringCB] eventCallback to call when a line on users phone rings - old style usage only, not used if first param is an array of functions
[upCB] eventCallback to call when a line on users phone is answered - old style usage only, not used if first param is an array of functions
[deadCB] eventCallback to 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

Param Type Default Description
number number to dial
[line] number 0 line index (zero based)

SimpleCTI.hangup(id)

Hangup a call

Kind: static method of SimpleCTI

Param Type Description
id String ID of call to hangup

SimpleCTI.answer(id)

Answer a call

Kind: static method of SimpleCTI

Param Type Description
id String ID of call to answer

SimpleCTI~statusCallback

Status (initialisation) event callback

Kind: inner property of SimpleCTI

Param Type Description
ok Boolean true or false: true: API successfully started false: error condition
code number numeric API error code (status == false only)
text String textual explanation suitable for user display

SimpleCTI~eventCallback

Call event callback

Kind: inner property of SimpleCTI

Param Type Description
state String one of 'ring', 'up', 'dead' - new state of call
number String The Caller ID of the other party. Caution: may not be numeric in all cases
party String 'caller' or 'callee' - defines which role we are
call Object Raw underlying call object
line Object Raw underlying line object

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •