TIPS Viva WAZO: A New Beginning

Discussion in 'Developers' Corner' started by rjaiswal, Apr 23, 2016.

  1. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    I Have A Dream...

    [​IMG]

    [​IMG]

    [​IMG]
     
    #121 wardmundy, May 21, 2016
    Last edited: May 21, 2016
  2. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    Perhaps @Sylvain Boily can explain how we push the CALLERID(name) into the XiVO call log once we have obtained the information. Looks like the call log entry is being written before the DID subroutine is executed.
     
  3. atsak

    atsak Guru

    Joined:
    Sep 7, 2009
    Messages:
    1,738
    Likes Received:
    155
    Yes, I am; and you're right it's excellent. Hyper V is the hypervisor I use everywhere as you know; it's been good to me over the years and much cheaper than VMWare for enterprise deployments (which is also an excellent product but in my case is a waste of money). I just wanted to see this working there since it's what I use everywhere. There's a couple things I find a little counter intuitive compared to our other friends who write a GUI front end, and one that is tricky is the lack of support for failover on carriers for outbound. Admittedly that doesnt' work well in FPBX anyway but it's sometimes quite useful for the 5 minutes someone has an outage here and there.
     
  4. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    Happy Preakness: CallerID Superfecta Rides Again with XiVO

    Still a lot of work to do, but I think we're ready for a few pioneers now that we have four sources working. Four = Superfecta for you racetrack fans!

    This original release supports AsteriDex (if you've migrated your database to SQLite3 as documented in the Nerd Vittles tutorial), OpenCNAM (with or without credentials), BulkCNAM (with an API key), and TelcoData (city, state, and type of telco of the caller).

    Installation is easy. Log into your server as root and issue the following commands:
    Code:
    cd /
    apt-get -y install php5-xmlrpc
    wget http://incrediblepbx.com/cid-superfecta.tar.gz
    tar zxvf cid-superfecta.tar.gz
    rm -f cid-superfecta.tar.gz
    /etc/init.d/asterisk restart
    If you plan to use either OpenCNAM (in commercial mode) or BulkCNAM (which requires registration), then you'll need to sign up on their sites and obtain your credentials. Once you have them, edit /var/lib/asterisk/agi-bin/nv-cid-superfecta.php and plug them in.

    CallerID Superfecta on XiVO works differently. I've attempted to streamline the method for adding new sources so that others can join the party easily. All of the providers are stored in a single file: /var/lib/asterisk/agi-bin/nv-cid-superfecta.php.

    HINT: We could use some help. To add new ones, there are two steps:

    1. Add the provider to the array in line 140. It currently looks like this:
    Code:
    $source=array("AsteriDex","OpenCNAM","BulkCNAM","TelcoData");
    2. Add the chunk of code to handle the CNAM lookup for the provider after the existing sources. Here's a sample of the OpenCNAM code to give you some hints:
    Code:
       case "OpenCNAM":
        $query = "https://api.opencnam.com/v2/phone/" . $thenumber . "?account_sid=".$SID."&auth_token=".$TOKEN."&format=pbx";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $query);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
        $cidname = chr(34).curl_exec($ch).chr(34);
        curl_close($ch);
        if ($debug) :
         fputs($stdlog, "\nOpenCNAM CallerID Name result: " . $cidname . "\n\n" );
        endif ;
        if (strpos($cidname,"WIRELESS") !== false) :
         $cidname="";
        endif ;
        if (strpos($cidname,"OPENCNAM") !== false) :
         $cidname="";
        endif ;
        if (strpos($cidname,"PAYMNT REQUIRED") !== false) :
         $cidname="";
        endif ;
        break ;
    
    3. If the provider requires credentials, add the variables at the top of the file. The default credentials setup looks like this:
    Code:
    // insert your OpenCNAM account_sid and auth_token credentials below to use commercial CNAM lookups
    $SID="";
    $TOKEN="";
    // insert your BulkCNAM API key below to use commercial CNAM lookups
    $BULKCNAM_APIKEY="";
    //
    
    Please share your additions with us so that we can keep some consistency in the array numbering scheme. Here's why.

    The dialplan code for CallerID Superfecta can be found in /etc/asterisk/extensions_extra.d/cid-superfecta.conf. It can be edited within the XiVO GUI: IPX Configuration -> Configuration files and choose cid-superfecta.conf.

    The important line is line #9 which currently looks like this:
    Code:
    same = n,AGI(nv-cid-superfecta.php,${XIVO_SRCNUM},0-1-2-3)
    We store CNAM providers in an array (numbered 0-3 currently because there are 4 providers). You specify the sources to use and the order in which to find a CNAM match by adjusting the entry order and choice of content providers. It currently shows 0-1-2-3. That setup tells CallerID Superfecta to search for a matching CNAM entry in the following order and to quit once a CNAM match is found for the CallerID number. The order is...

    0 - AsteriDex
    1 - OpenCNAM
    2 - BulkCNAM
    3 - TelcoData

    If you only wanted to use BulkCNAM and TelcoData, then the string would be 2-3. OpenCNAM will use its free CNAM cache if you don't plug your credentials into the Superfecta PHP file. BulkCNAM doesn't have a free tier but they do give you a little money to try out the service. If a query comes up empty or says "Cellular Number" or "Payment Required", we strip those out and return CALLERID(name) to blank unless you include TelCo data which grabs the type of phone provider and the city and state of the calling number. Commercial CNAM lookups cost about a half a cent per lookup.

    In case you missed it...

     
    #124 wardmundy, May 21, 2016
    Last edited: May 22, 2016
  5. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    If you want CallerID CNAM info to appear in CDR records, one possible solution is to turn on Asterisk CDR reporting and use a SQLite3 database for the CDR records. This will populate /var/log/asterisk/master.db with the call records. You can extract them like this:
    Code:
    sqlite3 /var/log/asterisk/master.db "select * from cdr"
    To get this working, do the following:
    Code:
    cd /etc/asterisk
    sed -i 's|no|yes|' cdr.conf
    echo "[master]" >  cdr_sqlite3_custom.conf
    echo "table = cdr" >>  cdr_sqlite3_custom.conf
    echo "columns => calldate, clid, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield"  >>  cdr_sqlite3_custom.conf
    echo "values => '${CDR(start)}','${CDR(clid)}','${CDR(dcontext)}','${CDR(channel)}', '${CDR(dstchannel)}','${CDR(lastapp)}','${CDR(lastdata)}','${CDR(duration)}', '${CDR(billsec)}','${CDR(disposition)}','${CDR(amaflags)}', '${CDR(accountcode)}','${CDR(uniqueid)}','${CDR(userfield)}'" >>  cdr_sqlite3_custom.conf
    chown asterisk:www-data cdr_sqlite3_custom.conf
    chmod 660 cdr_sqlite3_custom.conf
    sed -i 's|noload => app_cdr.so|;noload => app_cdr.so|' modules.conf
    sed -i 's|noload => cdr_sqlite3_custom.so|;noload => cdr_sqlite3_custom.so|' modules.conf
    sed -i 's|noload => func_cdr.so|;noload => func_cdr.so.so|' modules.conf
    /etc/init.d/asterisk restart
    
    If you also want to turn on CSV logging, issue the following command as well:
    Code:
    cd /etc/asterisk
    echo "[csv]" >> cdr.conf
    echo "loguniqueid=yes" >> cdr.conf
    echo "loguserfield=yes" >> cdr.conf
    echo "accountlogs=yes" >> cdr.conf
    sed -i 's|noload => cdr_csv.so|;noload => cdr_csv.so|' modules.conf
    /etc/init.d/asterisk restart
    
    This will populate /var/log/asterisk/cdr-csv/Master.csv with your CDR records in the following order:

    <accountcode>,<src>,<dst>,<dcontext>,<clid>,<channel>,<dstchannel>,<lastapp>, \
    <lastadata>,<start>,<answer>,<end>,<duration>,<billsec>,<disposition>, \
    <amaflags>,<uniqueid>,<userfield>
     
    #125 wardmundy, May 22, 2016
    Last edited: May 22, 2016
  6. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
  7. KUMARULLAL

    KUMARULLAL Guru

    Joined:
    Feb 20, 2008
    Messages:
    203
    Likes Received:
    16
    I salute ward on relentlessly working on xivo to make everyone's life much easier by integrating many applications with xivo. The only downside I see is that xivo does not have any gui for building ivrs. To build complex, nested ivr system, everything has to be though about in great detail writing contexts and dialplans to suite your unique requirement. It would be nice if xivo offers gui for building ivrs.
     
    Sylvain Boily likes this.
  8. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    Give us a little time. :chef:
     
  9. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    AsteriDex for XiVO

    For those with the pioneering spirit, I think we're ready for you.

    [​IMG]

    Prerequisites. You must have the SQLite3 application installed from previous tutorials. You must have the IVR component installed in order to get the asteridex.sqlite database installed in /var/lib/asterisk/agi-bin. You need an outbound trunk configured for either NXXNXXXXXX or 1NXXNXXXXXX outbound calling. In other works, complete the first 3 Nerd Vittles tutorials before you begin.

    Installing the Software. Log into your server as root and issue the following commands:
    Code:
    cd /
    wget http://incrediblepbx.com/asteridex4-xivo.tar.gz
    tar zxvf asteridex4-xivo.tar.gz
    rm -f asteridex4-xivo.tar.gz
    /etc/init.d/asterisk restart
    /etc/init.d/nginx restart
    
    Configuring the Software. Before AsteriDex is usable for click-to-dial calling, you'll need to edit /var/www/html/asteridex4/config.inc.php and insert the extension and line to be used for outbound calls from the web interface. The default extension is 701. Look up the Line # associated with this user and plug it into the settings: $defaultLine="8zqnfdpw";

    Using the Software. The AsteriDex database is a SQLite3 database stored in /var/lib/asterisk/agi-bin. There's also a copy of the original Asteridex database stored there as well (in case you [or we] screw things up). To access AsteriDex, point your web browser to http://XiVO-ipaddress/asteridex4 from a location that is already in the Travelin' Man 3 WhiteList.

    This version supports Voice Dialing by Name. Just dial 411 and say the name of the company or person you wish to call. AsteriDex will attempt to find them in the SQLite3 database and connect the call after first calling you on the line set up above in the configuration step.

    AsteriDex is pure GPL code. Enjoy!
     
    #129 wardmundy, May 23, 2016
    Last edited: Jun 5, 2016
  10. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
    @wardmundy do you have a repository like github with all of your addons ? It will be fun to hack asteridex to use our contact server directly. Do you know our API about dird ? api.xivo.io section xivo-dird. It's possible to write a module to support sqlite3 as a backend for contacts too.
     
    wardmundy likes this.
  11. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
  12. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    Sorry, no GitHub repo for all of this. Just download the tarballs from incrediblepbx.com. Still laying track in front of the steaming locomotive, but we'll take a look at dird once we catch our breath. :driving:
     
  13. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
  14. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
    @wardmundy another question :) What the target for this addons ? The end user with only his contacts or to share contacts with everybody ?
     
  15. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    GPL2 or 3 whichever you prefer.
     
  16. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    It's typically for use office-wide with a single person maintaining it. It sits behind firewall whitelist so the real world can't see it or access it. Removing /usr/share/xivo-web-interface/www/asteridex4/admin makes the admin menu go away so it can be protected for general office-wide use. We've put the SQLite3 database in /var/lib.asterisk/agi-bin.

    We use AsteriDex for click-to-dial, speed dialing (00+some 3-digit code), and voice dialing by name with Google.
     
  17. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    14,432
    Likes Received:
    2,450
    AsteriDex for XiVO (using native XiVO Phonebook)

    @Sylvain Boily was kind enough to rework our AsteriDex code so that it could be used for Click-to-Dial with the native XiVO Phonebook that you'll find in the GUI at IPX Services -> Phonebook. This version of AsteriDex cannot (yet) be used with the 411 Voice Dialer. You cannot use BOTH this version and the SQLite3 version on the same server!

    [​IMG]


    Installation

    1. Log into XiVO as root and issue the following commands:
    Code:
    wget https://github.com/sboily/asteridex4/archive/0.1.5.tar.gz
    mkdir -p /usr/share/xivo-web-interface/www/asteridex4/templates_c
    tar xfvz 0.1.5.tar.gz --strip-components=1 -C /usr/share/xivo-web-interface/www/asteridex4/
    chown www-data /usr/share/xivo-web-interface/www/asteridex4/templates_c
    apt-get install smarty3
    cd /usr/share/xivo-web-interface/www/asteridex4/config
    nano -w config.inc.php
    2. Once the editor opens, stop there for the moment and log into the XiVO web interface with your browser.

    3. Go to a user account you've already created under IPBX Settings -> Users. Check Enable XiVO Client and add a Username and Password for the user to give access to AsteriDex. The Profile type doesn't matter for the moment so just choose Supervisor. SAVE your changes.

    4. Now add a webservice account with the ACLs shown below. Goto Configuration -> Web Services Access and click +. In the General tab, give the account a name (asteridex), a login name (asteridex), and a secure password (make1up). Click on the ACL tab and click + twice to add each of the following. Then click SAVE. NOTE: You'll need this login name and password in the next step!
    Code:
    confd.#
    ctid-ng.#
    5. Now switch back to your editor in the CLI. Replace the xivo_host entry with the IP address of your server. Then insert your user and pwd entries that you created in step #4. Save your changes: Ctrl-X, Y, then ENTER.

    NOTE: Latest release also available on GitHub.

    Operation

    1. Create entries in your Phonebook using the XiVO web interface: IPX Services -> Phonebook. Multiple phone numbers per account are supported!

    2. Access AsteriDex at: https://xivo-ipaddress/asteridex4/ (trailing slash is required!)

    3. Login using the username and password you created in Configuration step #3 above.

    4. Click on any entry to dial the number.

    5. Your extension associated with your User account (the one that you used to log in) will now ring.

    6. Answer the call on your local extension and the call to the AsteriDex number will be placed using the outbound route matching the dial string of the number in your Phonebook. If you enter a cellphone number, an office phone number, and a home phone number for someone in your Phonebook, these will display in AsteriDex in the same order. No indication at the moment as to type of phone, but we'll add it to the @Sylvain Boily wish list.

    Additional documentation available here:

    http://documentation.xivo.io/en/stable/cti_client/cti_client.html

    http://documentation.xivo.io/en/stable/cti_client/xlets/people.html

    http://documentation.xivo.io/en/stable/administration/phonebook.html

    http://documentation.xivo.io/en/stable/system/service_authentication/service_authentication.html

    http://documentation.xivo.io/en/stable/system/xivo-auth/xivo-auth.html
     
    #137 wardmundy, May 26, 2016
    Last edited: May 27, 2016
  18. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
    @wardmundy what do you need for 411 service ?
     
  19. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
  20. Sylvain Boily

    Sylvain Boily Active Member

    Joined:
    Apr 30, 2016
    Messages:
    258
    Likes Received:
    143
    Another bonus: i added a dockerfile. You need to configure your postgres DB to listening on 0.0.0.0 because it's not enabled by default. To run the dockerfile, read the README on the repo.
     
    wardmundy likes this.