Triggering a php script when a call comes in?

Status
Not open for further replies.

RustBoy

New User
Joined
Apr 13, 2011
Messages
97
Reaction score
0
I have written a php script that gets triggered when an inbound call comes in. It's working but I am having a problem when a caller goes into a call queue. If a call queue has three extensions it's triggering the script three times. I need it to only get triggered once when extension 7946 is called.

Is the extensions.conf file where this macro/php script trigger should go?

Code:
    ;
    ############################################################################
    ; Macros [macro]
    ; ############################################################################

    ; Rings one or more extensions.  Handles things like call forwarding and DND
    ; We don't call dial directly for anything internal anymore.
    ; ARGS: $TIMER, $OPTIONS, $EXT1, $EXT2, $EXT3, ...
    ; Use a Macro call such as the following:
    ;  Macro(dial,$DIAL_TIMER,$DIAL_OPTIONS,$EXT1,$EXT2,$EXT3,...)
    [macro-dial]
    exten => s,1,GotoIf($["${MOHCLASS}" = ""]?dial)

    ;PIXAR MOD dialecticphp.agi
    exten => s,n,AGI(dialecticphp.agi)


How should I modify the macro so it only get's trigger when a specific extension is called?

I tried this but it does not work:

Code:
exten => 7946,n,AGI(dialecticphp.agi)

Thanks.
 
Anyone?
 
How about putting something in your PHP to prevent the unwanted execution? If it sees this is a subsequent call don't let it execute.

If that won't work, sounds like you'll need to move it to a part of the dial plan that isn't getting executed every time the queue rings the extension.
 
Is there anyone out there that is knowledgeable in this area that can provide some clues on how to get this issue resolved?
 
I still don't get the overall image of your dialplan, but maybe you can try this approach:

create a custom context in extensions_custom.conf
[trigger-custom]
exten => 7946,1,AGI(dialecticphp.agi)
exten => 7946,2,Goto(ext-queues,<nr of queue in dialplan>,1)
exten => 7946,n,Hangup()

don't modify the extensions.conf, it is autogenerated.

Include this trigger-custom in the path the callflow passes.
For example:
If you use from-pstn in the route for the queues, try doing this:

in extensions_custom.conf:

[from-pstn-custom]
include => trigger-custom

I think this setup would work.
 
achilles said:
I still don't get the overall image of your dialplan, but maybe you can try this approach:

create a custom context in extensions_custom.conf
[trigger-custom]
exten => 7946,1,AGI(dialecticphp.agi)
exten => 7946,2,Goto(ext-queues,<nr of queue in dialplan>,1)
exten => 7946,n,Hangup()

don't modify the extensions.conf, it is autogenerated.

Include this trigger-custom in the path the callflow passes.
For example:
If you use from-pstn in the route for the queues, try doing this:

in extensions_custom.conf:

[from-pstn-custom]
include => trigger-custom

I think this setup would work.

I tried your suggestion but it did not trigger my PHP script.

I also tried putting my original macro in the extensions_custom.conf file but the system seems to totally ignore it. The only way that I have been able to get my macro to work at all was by modifying the extensions.conf file, adding this single line:

exten => s,n,AGI(dialecticphp.agi)

Why wont this work in the extensions_custom.conf file?

Is there a simple test that I can do to see if anything in the extensions_custom.conf works? For example, I see this in there:

[weather-wakeup]
exten => *61,1,Answer
exten => *61,2,AGI(nv-weather.php)
exten => *61,3,Hangup
exten => *62,1,Answer
exten => *62,2,AGI(wakeup.php)
exten => *62,3,Hangup

If I dial *61 from my extension should it do something? I tried it but nothing happens, it just hangs up on me.
 
I tried putting your suggestion in the extensions.conf file but it did not work there either. It failed to trigger the php script and it also sent callers straight to my voicemail without ringing my extension.
 
I did not setup weather, so i also get the same result as you do.
Try calling 1234, you should hear a welcome message.
if yes, your extensions sees the from-internal context.

Give your testextension the context: trigger-custom and try calling to 7946.
This should initiate the AGI and proceed to the queue.
If this works, you should be able to add this context to the desired routes.

Question: is 7946 the number of your queue or a SIP extension?

Because what i described only works for entering the queue.

-----

Now I think that you mean: when entering the queue and extension 7946 is ringing, the AGI should be run.
What needs to be done is:
You will need to use a different agentnumber in the queue e.g. 7950 (make sure this one is not in use)

[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,2,Dial(SIP/7946)
exten => 7950,n,Hangup()

;add line to context
[from-internal-custom]
.
..
...
include => trigger-custom

If this method is working for you it will still call the AGI more than 1 time depending on the ringstrategy used. The setup will be more complex, but do-able.
 
achilles said:
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,2,Dial(SIP/7946)
exten => 7950,n,Hangup()

;add line to context
[from-internal-custom]
.
..
...
include => trigger-custom

Thank you achilles for taking the time time to help me. Your code worked perfectly and solved the problem that we were originally having. It's also now working from the "extensions_custom.conf" file. Awesome!

Can you please explain what this part of your code is doing?

.
..
...

Thanks again for your help, I really appreciate it.
 
achilles said:
Question: is 7946 the number of your queue or a SIP extension?

Because what i described only works for entering the queue.

7946 is an extension in one of our call queues.

How would I modify your solution if I wanted the script to be triggered when an outside caller calls my DID number (extension 7946)? Can I do this without creating a custom queue specifically for that purpose?
 
RustBoy said:
achilles said:
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,2,Dial(SIP/7946)
exten => 7950,n,Hangup()

;add line to context
[from-internal-custom]
.
..
...
include => trigger-custom

Thank you achilles for taking the time time to help me. Your code worked perfectly and solved the problem that we were originally having. It's also now working from the "extensions_custom.conf" file. Awesome!

Can you please explain what this part of your code is doing?

.
..
...

Thanks again for your help, I really appreciate it.

the context [from-internal-custom] in extensions_custom.conf has some lines in it.
this i represented with the dots.
What i was trying to say was: Just add the line: include => trigger-custom
to the end of the context-content.
So, don't add dots, just add one line at the end of the context
 
achilles wrote:
the context [from-internal-custom] in extensions_custom.conf has some lines in it.
this i represented with the dots.
What i was trying to say was: Just add the line: include => trigger-custom
to the end of the context-content.
So, don't add dots, just add one line at the end of the context

Thanks, that's what I thought but I just wanted to make sure.

Can you tell I am a newbie? :blush:
 
RustBoy said:
achilles said:
Question: is 7946 the number of your queue or a SIP extension?

Because what i described only works for entering the queue.

7946 is an extension in one of our call queues.

How would I modify your solution if I wanted the script to be triggered when an outside caller calls my DID number (extension 7946)? Can I do this without creating a custom queue specifically for that purpose?
So basically you want the AGI to run anytime this extension is called.
You can do:

Open the extension in FreePBX.
Locate the dial field.
It should be sth like: SIP/7946
You can change it to: SIP/7946&Local/7950@trigger-custom

In this case your trigger-custom context is:
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,n,Hangup()

which you also include in [from-internal-custom]for testing purposes.
<With this method you'll have to use 7946 in your queue>


or...

you can do:
in freepbx dial field for ext 7946: Local/7950@trigger-custom
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,2,Dial(SIP/7946)
exten => 7950,n,Hangup()

and the include in from-internal-custom only for testing purpose (not really needed).
<With this method you'll have to use 7946 in your queue>


or...

many other ways which will make things much more complicated.
Look if this helps you.
 
achilles said:
Open the extension in FreePBX.
Locate the dial field.
It should be sth like: SIP/7946
You can change it to: SIP/7946&Local/7950@trigger-custom

In this case your trigger-custom context is:
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,n,Hangup()

which you also include in [from-internal-custom]for testing purposes.
<With this method you'll have to use 7946 in your queue>


or...

you can do:
in freepbx dial field for ext 7946: Local/7950@trigger-custom
[trigger-custom]
exten => 7950,1,AGI(dialecticphp.agi)
exten => 7950,2,Dial(SIP/7946)
exten => 7950,n,Hangup()

and the include in from-internal-custom only for testing purpose (not really needed).
<With this method you'll have to use 7946 in your queue>


or...

many other ways which will make things much more complicated.
Look if this helps you.

That worked great! I have a much better understanding of what is going on now and I am starting to see all kinds of exciting possibilities.

Your post has helped me immensely. Thank you very much!
 
How can I get information out of a php script and into a context that can forward the caller to my desired destination?

Let me explain a little better. I have created my own super-blacklist database that is a little more sophisticated than the one that is built into Elastix. I have a MySQL database with the following information:

SUPER-BLACKLIST
(example record)

> callers_number: 6194891437
> callers_name: ABC Investment Corp
> inbound_route: 888-555-1212
> send_to: 7681
> send_to_desc: telemarketer dump box
> comment: These people are telemarketers! They are a pain in the neck.

My php script knows that I want to send this caller to extension 7681. What I cannot figure out is how to get the data out of php and into a context so the caller goes to the desired destination.
 
would be good to write out callflow.
sth like:
- inbound call on 888-555-1212
- callerid is checked against records in mysqldb.
etc etc.

furthermore...do you have a php script allready?
maybe you can post it here.

I think this is solvable! :)
 
Status
Not open for further replies.

Members Online Now

Forum statistics

Threads
111,859
Messages
589,435
Members
164,700
Latest member
Apollo Cloud