⬆️ ⬇️

Writing a voice menu script for Asterisk

Hello!

I decided to write a short note on how we organized a voice menu for Asterisk in our company. The topic is most relevant for beginners in IP telephony. So, comrades habravchane, do not minus much, I also tried to help beginners.



What we need for this: pre-record 4 welcome messages:

1. Hello, you called the company Horns and Hoofs. To connect with an employee, dial his extension number or stay on the line.

2. The secretary cannot answer you, but you can contact the department that interests you. Click 1 - TS department, 2 - 1C programming, etc.

3. Unfortunately, the employee can not answer you. It will be redirected to his cell phone.

4. Unfortunately, the department staff cannot answer you. You can leave a voice message to the head of the department.



The scheme is as follows [I apologize in advance for the artistic part :) is not strong]

image

')

In our example, the voice menu is triggered when dialing 100.



So php-agi script itself:



#!/usr/bin/php -q

<?php

require('phpagi.php');

function auth($agii)

{

$phones = array(

"79521111111" => "101", // 1

"79112222222" => "102", // 2

"79213333333" => "901" // 901

);

$buffer='';

$dtmfwait=3000; //

$result=$agii->fastpass_get_data($buffer,"1",$dtmfwait,3);

$digits=$result['result'];

// 3

if(strlen($digits)==3)

{

if (($a=$agii->exec('Dial',"SIP/$digits,20,t"))!=0)

{

$status = $agii->get_variable("DIALSTATUS");

$agii->exec('NoOp',':::::::::::'.$status['data']);

//

if ( ($status['data'] == "NOANSWER") or ($status['data'] == "CHANUNAVAIL"))

{

$agii->stream_file("3");

foreach ($phones as $phone_1 => $phone_2) {

if($phone_2==$digits)

{

$agii->exec('Set',"_NUMBER=$phone_1");

$agii->exec('Dial','H323/9999999@prov,,M(bubble),m');

}

}

}

}

return;

}

//

// 0,



if((strlen($digits)==0) or ($digits=='0') or (strlen($digits)!=3)){

//

$path='/home/shares/asterisk/in/'.date("dmyHi").'.wav';

$agii->exec('MixMonitor',$path.',b');

// 15

if ($agii->exec('Dial',"SIP/000,15,t")!=0)

{

// ,

$result=$agii->fastpass_get_data($buffer,"2",$dtmfwait,3);

$digits=$result['result'];

switch ($digits) {

case 1:

$agii->exec('Dial',"SIP/101&SIP/102&SIP/103&SIP/104&SIP/105,,tT");

break;

case 2:

// 2 . 201.

if($agii->exec('Dial',"SIP/201&SIP/202&SIP/203,,tT")!=0)

{

$agii->exec('Voicemail','201');

}

break;



case 3:

$agii->exec('Dial',"SIP/301&SIP/302&SIP/303&SIP/304&SIP/305&SIP/306&SIP/307&SIP/308&SIP/309,,tT");

break;



case 4:

$agii->exec('Dial',"SIP/401&SIP/402&SIP/403&SIP/405&SIP/407&SIP/408,,tT");

$agii->break;

case 5:

$agii->exec('Dial',"SIP/005&SIP/006,,tT");

break;

case 6:

$agii->exec('Dial',"SIP/404,,tT");

break;

case 7:

$agii->exec('Dial',"SIP/009,,tT");

break;

default:

$agii->exec('Dial',"SIP/000,,tT");

}

}

}

// $agii->stream_file("2");

$agii->exec('Hangup');

return 0;

}

//

$agi = new AGI();

$agi->answer();

$agi->exec('NoOp','Starting main module AGI script');

//

auth($agi);

?>



Suppose that in the redirection to the cellular does not scare you:

$agii->exec('Set',"_NUMBER=$phone_1");

$agii->exec('Dial','H323/9999999@prov,,M(bubble),m');




The simple fact is that our Voip provider cannot otherwise provide access to the “city”. The article on setting up Mango Office (Our Voip Provider) is here



PS I did not find how beautifully to arrange <"Code">.

PS2 Honestly not enough karma perenseti in another blog.

Source: https://habr.com/ru/post/77634/



All Articles