how to add voicemail capability in a2billing

if you use a2billing for your device2phone and peer2peer,and did calls
when PSTN call the sip device from did calls
or other sip friend call the sip device, if called is unavailable,or busy ,you may want the call goto voicemail,so caller can record voicemail,and voicemal will be sent to called's email

1. you must use asterisk realtime architecture ,because you cannot add 1000+ lines in voicemail.conf by hand,so I use mysql and cron job

CREATE TABLE `voicemail_users` (
`uniqueid` int(11) NOT NULL auto_increment,
`customer_id` int(11) NOT NULL default '0',
`context` varchar(50) NOT NULL default '',
`mailbox` varchar(15) NOT NULL default '0',
`password` varchar(4) NOT NULL default '8888',
`fullname` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`pager` varchar(50) NOT NULL default '',
`stamp` timestamp(14) NOT NULL,
PRIMARY KEY (`uniqueid`),
KEY `mailbox_context` (`mailbox`,`context`)
) TYPE=MyISAM;

below is cron job,it will syncronize a2billing tables with voicemail_users

truncate table voicemail_users;
insert into voicemail_users(customer_id,context,mailbox ,fullname,email)
select A.id_cc_card,'default',A.name, concat(B.lastname,' ',B.firstname),B.email from cc_sip_buddies A,cc_card B where A.id_cc_card =B.id ;

2. config in extconfig.conf
voicemail =>mysql,mya2billing,voicemail_users

3. in extensions.conf

[a2billing]
exten => _X.,1,GotoIf($["${EXTEN}" = "9000"]? 7)
exten => _X.,2,NoOp(nothing)
exten => _X.,3,Answer
exten => _X.,4,Wait(1)
exten => _X.,5,DeadAGI(a2billing.php|1)
exten => _X.,6,Hangup
exten =>_X.,7,VoicemailMain()
exten =>_X.,8,Hangup

it means if sip user/friend dial 9000 ,it willcheck his voicemail box,also he can change voicemail password(default '8888');

4. next you will change in agi processing,when
call _sip_iax_buddies () or call_did() ,if call status is unavaiable or busy or chann unavialble, u make the call to voicemal,I did as below

if (($dialstatus =="CHANUNAVAIL") || ($dialstatus == "CONGESTION") ||($dialstatus == "NOANSWER") )
{

// The following section will send the caller to VoiceMail with the unavailable priority.
$did_number = "u".$this->destination;
$this -> write_log("[STATUS] CHANNEL UNAVAILABLE - DIVERT TO VOICEMAIL ($did_number)");
$agi-> exec(VoiceMail,$did_number);

}

if (($dialstatus =="BUSY") )
{

// The following section will send the caller to VoiceMail with the busy priority.
$did_number = "b".$this->destination;
$this -> write_log("[STATUS] CHANNEL UNAVAILABLE - DIVERT TO VOICEMAIL ($did_number)");
$agi-> exec(VoiceMail,$did_number);
}

there're some occurence of above modification in Class.A2Billing.php

then your voicemail should work
1. when someone call the device,if unavailable,busy,chann unavaible, he will goto voicemail,the voicemail will be sent to the emailbox
2. the called can check voicemail by a. email,b. dialing 9000

mysql -uroot -pxxxx -Da2billing

drop view voicemail_users |
CREATE VIEW `voicemail_users` AS select `cc_sip_buddies`.`id` AS `uniqueid`,`cc_sip_buddies`.`id` AS `id`,`cc_sip_buddies`.`id_cc_card` AS `id_cc_card`,_latin1'a2billing' AS `context`,`cc_sip_buddies`.`name` AS `mailbox`,`cc_card`.`vmpass` AS `password`,`cc_card`.`lastname` AS `fullname`,`cc_card`.`email` AS `email`,_latin1'' AS `pager`,now() AS `stamp` from (`cc_sip_buddies` join `cc_card`) where (`cc_sip_buddies`.`id_cc_card` = `cc_card`.`id` and `cc_card`.`vm_activated`='t') |
delimiter ;