Create Voicemail from PHP script

Hi guys
I am writing a PHP script that will create a user extension and voicemail for users,
I can’t seem to find the function that creates voicemails

Can anyone help?

thanks

Avremy

There is no function for this. The voicemail config file is one of the only files that has to be handled directly. When you set up a new voicemail in Asterisk you have to do two things for it:

  1. Add the account to voicemail.conf
  2. Create the folder structure for the account.

And then , the hardest bit, create at least two files, a msgnnnn.txt file that describes the 'state’s of the voicemail, then files named msg0000. {WAV,wav,gsm} that contain the appropriate audio content. Then the nnnn needs to be replaced with a 4d(or 3) digit 0 padded integer that is 1 higher than the highest one already there, (0 based, so 0000 if none there) , the file should be read/writable by the asterisk user.

www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/Voicemail_id263499.html

itp-asterisk.pbworks.com/w/page/10029294/Tutorial

And here a post that kind of covers all the quirkiness of comedianmail

www.oneharding.com/voip/asterisk_voicemail_scripts.html

OK, no. They would use the default system greetings if they were not found. The msg000x.txt and .wav are only created when a voicemail is LEFT. Has nothing to do with creating the voicemail account or it being active.

The VoiceMail() app will do all the needed stuff to create those .txt and .wav files when the voicemail is left by the caller.

That would be how you interpret the OP’s post , literally “. . I can’t seem to find the function that creates voicemails . . .” which was my part of the answer.

But actually the first bit “. . t that will create a user extension . . .” would liklely be answered with the “fwconsole bulkimport -t extensions file.csv” functionality which itself would create the voicemail box if the file.csv was “well formed”

Well the real question is, why is a script needed to do what is already provided by FreePBX? Either via the GUI or the fwconsole commands.

@avremy, there is a lot of php code in

/var/www/html/admin/modules/bulkextensions/

including a template.csv, There is a “wrapper” to it in fwconsole bulkimport . . . . You can do it either way, but read the code for any exceptional treatments perhaps necessary and the minimum fields needed in .csv file you build.

@BlazeStudios, I have a Program that needs to dynamically create Extensions with VMs on a FreePbx Server with an of API,

For those who need this, I managed to do this by using the Bootstrap feature,

<?php                                             
                                                  
$bootstrap_settings = array();                    
$bootstrap_settings['freepbx_auth'] = false;      
include '/etc/freepbx.conf';                      
                                              

$user = array(                                                 
"extension" => $extension,                                     
"name" => $name,                                               
"password" => base64_encode(openssl_random_pseudo_bytes(30))   
);

$vmarray = array(

  "display"  => "extensions"  ,
  "extdisplay" => $extension ,
  "action" => "edit" ,
 "tech" => "" ,
 "hardware" =>  "",
 "name" => $name ,
 "outboundcid" =>  "",
  "userman_directory" => "1" ,
  "userman_assign" => "none" ,
  "userman_password" => "f09139b1263324de7f4a158ec16e3e41"  ,
 "vm" => "enabled" ,
 "vmpwd" =>  "",
 "passlogin" => "passlogin=no"  ,
 "novmstar" => "novmstar=no" ,
 "email" => $email ,
 "pager" =>  "",
 "attach" => "attach=yes" ,
 "saycid" => "saycid=no" ,
 "envelope" => "envelope=no" ,
 "vmdelete" => "vmdelete=no" ,
 "options" => "" ,
 "vmcontext" => "default" ,
 "vmx_state" => "disabled" ,
 "vmx_option_0_number" =>  "",
 "newdid_name" =>  "",
 "newdid" =>  "",
 "newdidcid" =>  "",
 "cid_masquerade" =>  "",
 "sipname" =>  "",
 "ringtimer" => "15" ,
 "rvolume" => "" ,
 "cfringtimer" => "0" ,
 "concurrency_limit" => "3" ,
 "callwaiting" => "disabled" ,
 "call_screen" => "0" ,
 "emergency_cid" => "" ,
 "recording_in_external" => "recording_in_external=dontcare" ,
 "recording_out_external" => "recording_out_external=dontcare" ,
 "recording_in_internal" => "recording_in_internal=dontcare" ,
 "recording_out_internal" => "recording_out_internal=dontcare" ,
 "recording_ondemand" => "recording_ondemand=disabled" ,
 "recording_priority" => "10" ,
 "dtls_enable" => "no" ,
 "dtls_certificate" => "1" ,
 "dtls_verify" => "fingerprint" ,
 "dtls_setup" => "actpass" ,
 "dtls_rekey" => "0" ,
  "goto0" => "" ,
 "noanswer_dest" => "goto0" ,
 "noanswer_cid" =>  "",
 "goto1" =>  "",
 "busy_dest" => "goto1" ,
 "busy_cid" => "" ,
 "goto2" =>  "",
 "chanunavail_dest" => "goto2" ,
 "chanunavail_cid" =>  "",
 "pinless" => "disabled" ,
 "extension" => $extension


);

core_users_add($user);
 core_devices_add(255,'sip','','fixed',255,$name);
 voicemail_mailbox_add($extension,$vmarray);
  shell_exec('fwconsole reload');
?>

Hope this helps someone, and thanks guys for the responses :smile:

2 Likes