AEL: 簡易Queue及整合AGI

    這個案例主要是用 AEL 開發 dialplan,其中需要與指定 AGI 傳遞參數,以及 Static Queue 與 Dynamic Queue 的操作。

    更多文章:

    AEL Script:

    //
    // 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);
        //391 => Dial(SIP/391);  //** this line is only used for debugging ** 
        //392 => Dial(SIP/392);  //** this line is only used for debugging **
        _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/391); //** 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
                 //Set(QUEUE_NUMBER=808);      //** this line is only used for debugging **
                 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 => {
              Set(err=${QUEUE_VARIABLES(${QUEUE_NUMBER})});
              Noop(----- Number of calls currently in the queu: ${QUEUECALLS} -----);
              if( ${QUEUECALLS} = 0 ) {
                  Noop(------ Calling Ring-Group ------);
                  Dial(${RINGGROUP},${DIAL_TIMEOUT},M(ael_callanswered));
              }
              Noop(------ There is any calls in the queue or no answered on Ring-Group, add the caller to queue ------);
              goto ael_ivr-queue|s|1;
              Hangup();
        };
        h => goto ael_ivr-callterminated|s|1;
    };
    
    context ael_ivr-queue {
        s => {
              Answer();
              Wait(1);
              Noop(------ Starting Queue ------);
              WaitExten(2,);
              Queue(${QUEUE_NUMBER},t,,,,,ael_callanswered);
              Hangup(); 
        };
        1 => {
              goto ael_ivr-systemvoicemail|s|1;
        }; 
        h => goto ael_ivr-callterminated|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();
        }
    }
    
    context macro-ael_callanswered {
        s => {
              Wait(1);
              Noop(------ AGI: CallAnswered ------);
              AGI(agi://localhost/CallAnswered.agi);
        }
    }
    
    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;
            }
        }
    }
    
    
    // EOF
    

    queues.conf:

    [general]
            persistentmembers=yes
            shared_lastcall=yes
            updatecdr=no
            monitor-type=MixMonitor
    
    ; Static Queue
    [801]
            announce-frequency=15
            announce-holdtime=no
            announce-position=yes
            music=default
            autofill=no
            eventmemberstatus=no
            eventwhencalled=no
            joinempty=yes
            leavewhenempty=no
            maxlen=0
            memberdelay=0
            penaltymemberslimit=0
            periodic-announce-frequency=15
            queue-callswaiting=queue-callswaiting
            queue-thankyou=queue-thankyou
            queue-thereare=queue-thereare
            queue-youarenext=queue-youarenext
            reportholdtime=no
            retry=5
            ringinuse=yes
            servicelevel=60
            strategy=ringall
            timeout=15
            timeoutpriority=app
            timeoutrestart=no
            weight=0
            wrapuptime=0
            context=ael_ivr-queue
            setqueuevar=yes
            member=SIP/300,1
            member=SIP/301,1
            member=SIP/302,1
    
    ; Dynamic Queue
    [802]
            announce-frequency=15
            announce-holdtime=no
            announce-position=no
            music=default
            autofill=no
            eventmemberstatus=no
            eventwhencalled=no
            joinempty=yes
            leavewhenempty=no
            maxlen=0
            memberdelay=0
            penaltymemberslimit=0
            periodic-announce-frequency=15
            queue-callswaiting=queue-callswaiting
            queue-thankyou=silence/1
            queue-thereare=queue-thereare
            queue-youarenext=queue-youarenext
            reportholdtime=no
            retry=5
            ringinuse=yes
            servicelevel=60
            strategy=ringall
            timeout=15
            timeoutpriority=app
            timeoutrestart=no
            weight=0
            wrapuptime=0
            context=ael_ivr-queue
            setqueuevar=yes
    
    標籤 (Edit tags)
    • No tags

    文件 2

    文件大小日期附件上傳者 
     agi.pdf
    無描述
    308.49 KB13:51, 20 Aug 2011alang動作
     ivr-2.pdf
    無描述
    106.49 KB13:51, 20 Aug 2011alang動作
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core