script in IVR ?

Discussion in 'General' started by newnet82, Apr 27, 2009.

  1. newnet82

    Joined:
    Apr 25, 2009
    Messages:
    57
    Likes Received:
    0
    Hi,

    Well, I have 2 ivr (ivr_level1 and ivr_level2).
    All is running fine.

    Now, I want to add a script that intercept the phone number before the ivr_level1 answer and gives the voice message.
    I want my script test the phone number. Something like :

    If this phone number is in my database
    then
    I call directly the extension associate
    else
    I give the hand to IVR_level1.

    Is it possible ?
    If yes, what should I do ?

    Thx
     
  2. rafael

    Joined:
    May 14, 2007
    Messages:
    1,454
    Likes Received:
    1
    I think it is possible, but you would have to learn more about dial plan and agi scripting. Google for it.

    Regards,

    Rafael
     
  3. Bob

    Bob

    Joined:
    Nov 4, 2007
    Messages:
    2,400
    Likes Received:
    1
    newnet82,

    There is no simple way to get this setup, however, as a start, one of the ways you could look at this is by looking at the BlackList, which has some of the base functionality that you need.

    The macros for the blacklist is in the extensions_addtional.conf. You could use this as your starting block. I would copy the relevant parts of the blacklist macros to the extensions_custom.conf and maybe call it Whitelist.

    As you need addtional functionality, it is not a simple cut and paste, but at least most of the basics of the coding are there. I would set it up as a custom destination so that it can be checked before IVR1, if it fails to find the number, progress as normal. If it finds the number in the database then ring extension direct.

    So flow would be as follows

    Incoming call
    V
    Whitelist App (custom destination)
    V
    If phone matches > Call extension listed in Database
    V
    IVR1

    So that you are under no illusions, you would need to add a new table to the database, that table would contain the CID, and the extension associated with the CID (basically a table with two fields)

    You could use the Blacklist Macros (the ones that add the numbers to the black list database) to add the CID and extension. Naturally you would be renaming these to whitelist in the extensions_custom.conf, and adding a bit of code to add the extension that you want it to call to the database as well.

    With the correct coding, it should work quite well. This would allow you to add more numbers to the Whitelist using the *XX commands, as well as the extension it is supposed to dial direct. This would mean that it would be kept up to date with simple * commands, requiring no special XML or config files listing the phone numbers and extensions, and no need to access the Linux prompt.

    Hope it gives you something to look at....


    Bob
     
  4. newnet82

    Joined:
    Apr 25, 2009
    Messages:
    57
    Likes Received:
    0
    Hi,

    I found the solution.

    Because I'm working with perl I needed to install asterisk-perl module.

    After this installation, I create a agi script in perl and put it in
    /var/lib/asterisk/agi-bin with execution rights for all.

    This script (script.agi for the example) is

    Code:
    #!/usr/bin/perl
    use Asterisk::AGI;
    
    $AGI = new Asterisk::AGI;
    
    my %input = $AGI->ReadParse();
    
    my $callerid = $input{'callerid'};
    
    open(FIN, "< /tmp/liste.txt");
    $ext = "";
    while (<FIN>)
    {
       if (/$callerid/)
       {
          ($num, $ext) = split(/ /, $_);
    
          $AGI->verbose("Executing Dial $option\n", 3);
          $AGI->set_extension($ext);
          close(FIN);
          exit 0;
       }
    }
    
    close(FIN);
    
    exit 1;
    The file /tmp/liste.txt is a 2 columns file "caller(number) and extension(ToCall).

    Last step, in the file /etc/asterisk/extensions.conf, in the first line of the block
    [from-sip-external], I add the line :

    exten => _.,1,AGI(script.agi)

    I reboot.

    And that all.

    There is problem to modify /etc/asterisk/extensions.conf ?


    BR
     

Share This Page