Custom agi scripts in Elastix?

Discussion in 'General' started by isgur513, Sep 29, 2008.

  1. isgur513

    Joined:
    Sep 29, 2008
    Messages:
    1
    Likes Received:
    0
    Hi all,

    I have used Asterisk for a few years now and along with Asterisk, I have implemented various agi scripts that I call in my extensions.conf file. These include wake-up scripts, weather scripts, and other misc. features. Anyone know how to implement these into elastix?

    Thanks!
     
  2. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    I'm assuming that you're putting these scripts into var/lib/asterisk/agi-bin and giving them the correct permissions and ownership, and I'm also assuming that you have installed any "extras" that may be required to run the script (such as speech synthesis software, if it's needed). You'd probably do all that about the same way you have done it in the past, but then in etc/asterisk/extensions_custom.conf you'd put the code that calls the agi script. Here's a suggested template for a dialplan fragment in extensions_custom.conf

    [custom-my-script-name]
    exten => _.,1,Noop(Entering Custom Context: My Script Name Here)
    exten => _.,n,Ringing
    exten => _.,n,AGI(myscript.agi)
    exten => _.,n,GotoIf($["x${IVR_CONTEXT}" = "x"]?app-blackhole,hangup,1:${IVR_CONTEXT},return,1)
    exten => _.,n,Goto(app-blackhole,hangup,1)
    exten => h,1,Macro(hangupcall,)

    Change "my-script-name" in the context header and then the parts in red. Note that this contains code that, if called from an IVR, will return the caller to the IVR after the agi script executes, so they can make another selection if they like (if you don't want that, remove the line that has "${IVR_CONTEXT}" in it). A normal caller (not coming from an IVR) will get a hangup at the end of the call.

    Once you have done that, go to the Elastix GUI and select the PBX tab, then "Unembedded FreePBX", then the Tools tab (in the left-hand panel), then Custom Destinations. Make a new Custom Destination, in the first textbox enter this:

    custom-my-script-name,${EXTEN},1

    ...again changing the part in red. Be sure to give the Custom Destination a description, it is what will appear in dropdowns to identify the destination.

    Now you can use this destination from an IVR menu or any place that uses destinations. For example, if you want it to be dialable using a code (like an extension) then go into Misc Applications (under the Setup tab in Unembedded FreePBX, or under the PBX tab in Elastix) and create a new Misc Application. Under "Feature Code" put whatever you want people to dial to reach your script (try not to conflict with any existing codes or extension numbers!). As the Destination, look under "Custom Applications" and you should find your Custom Destination in the dropdown menu. Why is it called a Custom Destination in one module and a Custom Application in another? Who knows - it just is!

    It goes without saying that you need to submit any changes you make in FreePBX before you leave the page where you made them, otherwise you get to do it over!
     
  3. JohnyBeGood

    Joined:
    May 18, 2008
    Messages:
    134
    Likes Received:
    0
    Thanks wiseoldowl for taking time to write this howto!

    How about "Blocking Telemarketers in Asterisk with whocalled.us" http://asterisktech.ning.com/profiles/b ... ost%3A1361

    I've tried to combine your howto with the one above but didn't work out.
    I didn't know what to do with part that says "After calling the AGI,...."

    Also I didn't know how to implement above when the call comes in?
     
  4. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    JohnyBeGood, the biggest reason you are having issues is because the script on that page was made to work with plain old Asterisk, not FreePBX, and the code they use following the call to the AGI script is really just sample code that would not be applicable in FreePBX. As an aside, the AGI script makes some assumptions that may not always be valid (such as if the CallerID isn't exactly ten digits long, it's spam) and also does not implement a short timeout on the HTTP request (so if the site is slow to respond or non-responsive, your call processing is not delayed by more than a couple of seconds), so I personally would not use that AGI script as written, but that's just me.

    The difference is that in the sample AGI script I gave above, I assume that the call is completed (except for the hangup or redirect to another IVR choice at the end of the call) by code within the AGI script itself. This is most suitable for scripts that actually do something, such as play a recording or deliver some type of information using speech synthesis, within the AGI itself. However, what you are trying to do is something a bit different - you want to call the AGI script to determine if the call is likely to be from a known telemarketer, then pass or block it depending on that information.

    I would note that there is another service that may be more suitable for the purpose (if not now than maybe in the future), see the discussion at http://www.freepbx.org/forum/freepbx/us ... keters-etc (my post from earlier today may give you one thought as to how what you want to do could be implemented, note the 4th paragraph in particular).

    Anyway, keep in mind that scripts written for use with barebones Asterisk generally won't work with FreePBX without at least some tweaking. FreePBX (and, by extension, Elastix) does things a bit differently than standalone Asterisk.
     
  5. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    One other thought, if you insist on trying to use that script, then I believe that the following line would at least partially solve the issue of not delaying calls too much if the site happens to be slow or non-responsive:

    Code:
    $ua->timeout(2);
    
    That would cause the script to wait a maximum of two seconds for a response from the server. It should probably go right after the line "# Check the Whocalled.us WebSite" BUT be aware that simply adding that one line does not necessarily mean the script will work as you might expect when the server is inaccessible. Frankly, without going through the script with a fine-tooth comb (so to speak) I have no idea what would happen if the server times out - hopefully it would return a score of 0 but I don't know that for sure. I'm just pointing out that as that code is written, if the server becomes inaccessible then your incoming calls are just going to sit there waiting for whatever the default timeout is, and I'm pretty sure that's a lot longer than most callers would be willing to wait while listening to dead silence from your end.
    One reason I don't really care for that particular site is the requirement to register, and to provide username and password when doing a number lookup. Were it not for that, I might have a bit more enthusiasm for digging into this and maybe figuring out how to make it work correctly under FreePBX (not that this would ever be really high on my list of priorities).
     
  6. JohnyBeGood

    Joined:
    May 18, 2008
    Messages:
    134
    Likes Received:
    0
    Thanks for taking time to reply!

    Now after I read everything I can tell it needs lots of work and unfortunately I can't contribute much other then ideas.

    I think much easier way would be to have a cron job download nightly list of blocked numbers ie. www.Whocalled.us/list.txt and overwriting old file,
    and then either import that list into DB or have freePBX look into that file and to check if incoming number is on the list.
    What's your thought?
     
  7. Telco

    Joined:
    Oct 4, 2007
    Messages:
    275
    Likes Received:
    0
    I have handled this via a much simpler method.

    I created an IVR that tells the caller to press a button to continue. ie. Thanks for calling ABC company please press 2 to connect your call. OR something like that. Then I have the IVR hangup after a few seconds. Since 99% of all Telemarketers use AutoDialers the autodialers don't know to press a button. Therefore they are hungup on.

    Since I have implemented this (6 months now) I have had very very very few Telemarketer calls.
     

Share This Page