這個案例主要是用 AEL 開發 dialplan,其中需要與指定 AGI 傳遞參數,以及 Static Queue 與 Dynamic Queue 的操作。
更多文章:
// // Main IVR Scripts // Author: alang.hsu[AT]gmail.com // context from-internal { 55 => { Playback(demo-echotest); Echo; Playback(demo-echodone); } 1234 => { SayUnixTime(); Hangup(); } 300 => Dial(SIP/300,20,t); 301 => Dial(SIP/301,20,t); 302 => Dial(SIP/302,20,t); _0. => { DIAL(SIP/${EXTEN}@faktortel); Congestion(); } h => Hangup(); includes { ael_queue-loginout; } } context ael_ivr-from-trunk { _X. => { Set(FROM_DID=${EXTEN}); Set(CDR(accountcode)=${EXTEN}); Set(CALLERID(name)=${SIP_HEADER(To)}); // put the recordings on /var/lib/asterisk/sounds/custom/ Set(MSG1=generic-voicemail); Set(CLIENT_MSG=recordings/${FROM_DID}); Set(RINGGROUP=SIP/300&SIP/301&SIP/302); //Set(RINGGROUP=SIP/300&SIP/391&SIP/302); //** this line is only used for debugging ** Set(DIAL_TIMEOUT=10); set(VM_EMAIL=kd@virtualcto.com.au); Set(QUEUE_NUMBER=802); // 801: static queue ; 802: dynamic queue AGI(agi://localhost/TimeOfDayHandler.agi); //Set(X-YPC-STATUS=OK); //** this line is only used for debugging ** Verbose(Returned from agi, status= ${X-YPC-STATUS}); switch(${X-YPC-STATUS}) { case UNKNOWN: Verbose(YPC-UNKNOWN); Playback(ss-noservice); goto ael_ivr-callterminated|s|1; case UNAVAILABLE: Verbose(YPC-UNAVAILABLE); goto ael_ivr-clientvoicemail|s|1; default: Verbose(YPC-OK); goto ael_ivr-findagent|s|1; }; Hangup(); }; }; context ael_ivr-findagent { s => { Noop(------ Calling Ring-Group ------); Dial(${RINGGROUP},${DIAL_TIMEOUT}); Noop(------ No answered on Ring-Group, add the caller to queue ------); goto ael_ivr-queue|s|1; Hangup(); }; }; context ael_ivr-queue { s => { Answer(); Wait(1); Noop(------ Starting Queue ------); WaitExten(2,); Queue(${QUEUE_NUMBER},t); Hangup(); }; 1 => { goto ael_ivr-systemvoicemail|s|1; }; }; context ael_ivr-systemvoicemail { s => { Playback(recordings/${MSG1}); Noop(------------- Minivm Record -------------); minivmRecord(${VM_EMAIL},b); goto goahead|1; }; goahead => { Verbose(Recording file name: ${MVM_FILENAME}); Verbose(The duration of the message: ${MVM_DURATION}); Set(X-YPC-VM-FILENAME=${MVM_FILENAME}.WAV); Set(X-YPC-VM-DURATION=${MVM_DURATION}); AGI(agi://localhost/SystemVoicemail.agi); //AGI(agi://localhost/SystemVoicemail.agi,${MVM_FILENAME},${MVM_DURATION}); goto ael_ivr-callterminated|s|1; }; h => { Noop(------------- HANGUP during voicemail recording -------------); goto goahead|1; Noop(---Minivm DONE----); }; }; context ael_ivr-clientvoicemail { s => { Playback(${CLIENT_MSG}); Noop(------------- Minivm Record -------------); minivmRecord(${VM_EMAIL},b); goto goahead|1; }; goahead => { Verbose(Recording file name: ${MVM_FILENAME}); Verbose(The duration of the message: ${MVM_DURATION}); Set(X-YPC-VM-FILENAME=${MVM_FILENAME}.WAV); Set(X-YPC-VM-DURATION=${MVM_DURATION}); AGI(agi://localhost/ClientVoicemail.agi); //AGI(agi://localhost/ClientVoicemail.agi,${MVM_FILENAME},${MVM_DURATION}); goto ael_ivr-callterminated|s|1; }; h => { Noop(------------- HANGUP during voicemail recording -------------); goto goahead|1; Noop(---Minivm DONE----); }; }; context ael_ivr-callterminated { s => { Noop(------ AGI: Call Terminated ------); AGI(agi://localhost/CallTerminated.agi); Hangup(); }; }; context ael_queue-loginout { 11 => { Answer(); Set(queue-announce-success=1); Set(AGENT_NUMBER=${CALLERID(num)}); Set(DYNAMIC_QUEUE=802); &ael_queue-addremove(${DYNAMIC_QUEUE},10,I${AGENT_NUMBER}); &ael_queue-success(I${AGENT_NUMBER}); Hangup(); } 22 => { Answer(); Set(queue-announce-success=1); Set(AGENT_NUMBER=${CALLERID(num)}); Set(DYNAMIC_QUEUE=802); &ael_queue-addremove(${DYNAMIC_QUEUE},10,O${AGENT_NUMBER}); &ael_queue-success(O${AGENT_NUMBER}); Hangup(); } } macro ael_queue-addremove(queuename,penalty,exten) { switch(${exten:0:1}) { case I: // Login AddQueueMember(${queuename},SIP/${exten:1},${penalty}); break; case O: // Logout RemoveQueueMember(${queuename},SIP/${exten:1}); break; case P: // Pause PauseQueueMember(${queuename},Local/${exten:1}@agents); break; case U: // Unpause UnpauseQueueMember(${queuename},Local/${exten:1}@agents); break; default: // Invalid Playback(invalid); break; } } macro ael_queue-success(exten) { if( ${queue-announce-success} > 0 ) { switch(${exten:0:1}) { case I: Playback(agent-loginok); Hangup(); break; case O: Playback(agent-loggedoff); Hangup(); break; } } }