Asterisk AMI – Sending MWI (Using SIPnotify)

Sending a SIP MWI (Message Waiting Indicator) using Asterisk AMI is possible, but the syntax is just really confusing (and not documented), after rummaging through the source code for a bit I worked it out.

We need to use the SIPnotify AMI Action. The tricky part is getting the syntax right:

Action: SIPnotify
ActionID: 1231541512
Channel: peername
Variable: Event=message-summary,Content-Type=application/simple-message-summary,Content=Messages-Waiting: yes,Content=Voice-Message:1/3
Notice: That that we need to set the the Variable argument “Content” in order to set the body, furthermore “Content” does not accept newlines “\n” so we have to set more than one “Content” – pretty confusing yes.

Here is a complete example of some PHP code that uses Joshua Hatfield’s very helpful flowAPI Class which makes working with the Asterisk Manager Interface very easy in PHP.

        $username="somesippeerusername";
        $total_messages=5;
        $unheard_messages=2;
   
        $waiting="no";
        if($unheard_messages > 0){                                                                     
            $waiting="yes";                                                                            
        }                                                                                              
    
         $body1="Messages-Waiting: $waiting"; 
         $body2="Voice-Message: $unheard_messages/$total_messages";
    
        $ami=new floAPI();                                                                           
        $params=array(
        "ActionID"=>rand(12,12),
        "Channel"=> $username,
        "Variable"=>"Event=message-summary,Content-Type=application/simple-message-summary,Content=$body1,Content=$body2");
        
       $ami->request("SIPnotify",$params);                                                             
       $ami->close();

Alternative ways of sending MWI

You could use a different SIP messaging program (besides Asterisk) to send a SIP MWI Notify.

Using SipSak
http://www.voip-info.org/wiki/view/Asterisk+Realtime+MWI+Hacks

Using PHPSip
https://code.google.com/p/php-sip/

Just make sure you use the right syntax as specified here.

Note: For most Asterisk setups simply set “mailbox”in sip.conf and asterisk will send MWI behind the scene: see here. This is for those using VM outside of asterisk or have other custom needs.

References:
https://issues.asterisk.org/jira/browse/ASTERISK-13089?jql=text%20~%20%22SIPnotify%22
https://issues.asterisk.org/jira/browse/ASTERISK-23283?jql=text%20~%20%22SIPnotify%22
http://forums.asterisk.org/viewtopic.php?f=1&t=91498&start=0&hilit=SIPnotify
https://wiki.asterisk.org/wiki/display/AST/ManagerAction_SIPnotify

Asterisk – ODBC + CDR + Mysql on Ubuntu

We recently switched from using cdr_mysql on Asterisk (now depreciated) to crd_obdc + cdr_adaptive_odbc to store CDR logs to MySQL. Below is the process for doing so.

Install needed libraries.

1. apt-get install libmyodbc unixodbc-bin
2. sudo apt-get install unixODBC unixODBC-dev

Lookup socket:

mysqladmin -u root -p version

Update /etc/odbc.ini – set socket to location found in above command:

[MySQL-ivr_test]
Description     = ivr_test MySQL ODBC
Driver          = MySQL
Socket          = /var/run/mysqld/mysqld.sock
Server          = localhost
User            = root
Password        = password
Port            = 3306
Database        = ivr_test
Option          = 3

Find you driver & setup paths:

find / -name 'lib*odbc*.so'

and then update /etc/odbcinst.ini (look for the two files “libmyodbc.so” & “libodbcmyS.so” from the above command and then set the Driver, Setup fields correspondingly):

[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1

Install the ODBC driver:

odbcinst -i -d -f /etc/odbcinst.ini

Install your system DSN:

odbcinst -i -s -l -f /etc/odbc.ini

Test:

odbcinst -s -q

Try and connect:

isql -v MySQL-ivr_test MYSQLUSER MYSQLUSERPASSWORD

Almost there, now on the asterisk side of things:

Update /etc/asterisk/res_odbc.conf

[MySQL-ivr_test]                                                                                                      
enabled => yes                                                                                                        
dsn => MySQL-ivr_test                                                                                                 
username => username                                                                                                      
password => paswordhere                                                                                           
preconnect => yes 

Update /etc/asterisk/cdr_adaptive_odbc.conf

[first]                                                                                                          
connection=MySQL-ivr_test                                                                                             
table=users_call_logs                                                                                                 
alias start => calldate

 

See also IVR set up in Asterisk here.

Thanks to:
http://www.kaffeetalk.de/how-to-setup-and-configure-mysql-with-unixodbc-under-ubuntu-14-04/
http://nerdvittles.com/?p=604
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html