FreePBX | Register | Issues | Wiki | Portal | Support

Execute System Command when Extension is dialed


(Albertlauts) #1

I want to be able to execute a system() call every time an extension is dialed.

Can anyone suggest best practice for doing this in a way that will not be overwritten by upgrades or configuration changes in the GUI?

Thanks in advance.


(Dave Burgess) #2

An oldie but a goodie:

Write a custom context that supplements the “lrom-local” context that calls and uses an ARI to run a program that can be written in “C”, PHP, or PERL. From there, you can simulate whatever you want to make happen and still have access to the context environment. You can also, if that’s too much to ask, use PERL and PHP to run various 'system()"-like functions.


(Albertlauts) #3

Thank you for your response.

When I am looking for is the process for extending the context in the custom configuration files


(Cyber Sleuth) #4

Is this what you mean?

https://wiki.freepbx.org/plugins/servlet/mobile?contentId=26509798#content/view/26509798


(Albertlauts) #5

I have never used CUSTOM DESTINATIONS for this before. The CUSTOM DESTINATIONS module allows you to point various locations to your custom extensions. But, I have never used it in-line like I want to do here.

To clarify… I want to run a SYSTEM() command every time someone dials the extension of another user.

The process for completing a call to a user’s extension is already included in the “from-internal” context. But, to include the line “exten => 200,n,system(somescript.sh)” gets overwritten when anything changes in FreePBX. That being said, how can I ensure that my system() call gets run every time someone’s extension gets dialed?


(Cyber Sleuth) #6

You would create a custom context with your commands in the custom conf file.

You would use the wiki I linked above to define that custom context in FreePBX. This will make the GUI aware of your custom context.

On the applicable inbound route, have it point at your custom destination.

If needed, use the return option. You could send it to another step from within the GUI (message, extension, etc.).

Is that what you’re trying to accomplish?


(Albertlauts) #7

Our inbound routes get answered by an IVR and the IVR permits the caller to transfer to the operator (a ring group) or directly to the agent’s extension.

Once the extension is dialed, I need asterisk to be able to execute a system() command in order to provide information to a screen pop application outside of FreePBX/Asterisk.

I don’t see how to do this with custom destinations…


#8

You could have the inbound route go to your custom destination. The custom destination could handle the customer prompt and routing from within the custom destination (no IVR).

To use the custom destination, per the wiki instructions, you need to make a context in the custom conf file, add your dialplan to the context, then make an entry in the custom destination module (the same context).

Once you do that, the custom destination becomes a selectable option in the GUI, like an announcement, or IVR. The custom destination would not be overwritten with updates. If you need help actually writing a custom context, I think that is a different question than what you had originally asked.

If the data you want to send can be sent via URL, the Zulu service might be a nice option. You can use it for a lot of things, including a CTI gateway. Its is a commercial module, but is really well done, and would let you send channel variables via URL to user computers, all from the GUI.


(Albertlauts) #9

In the extensions_additional.conf file, dialplan extensions include custom contexts so that the contexts can be customized to execute additional or alternate things.

If I put

[from-internal-custom]
exten => _XXX,1,NoOp(Albert Was HERE boooooeeeeeyyyyyyy)

dialing an extension will hit this part of the dialplan and run

== Using SIP RTP CoS mark 5
– Executing [201@from-internal:1] NoOp(“SIP/200-0000004a”, “Albert Was HERE boooooeeeeeyyyyyyy”) in new stack
– Executing [201@from-internal:2] Macro(“SIP/200-0000004a”, “exten-vm,novm,201,0,0,0”) in new stack

BUT, this replaces the command previously at priority 1

== Using SIP RTP CoS mark 5
– Executing [201@from-internal:1] Set(“SIP/200-0000004c”, “__RINGTIMER=15”) in new stack
– Executing [201@from-internal:2] Macro(“SIP/200-0000004c”, “exten-vm,novm,201,0,0,0”) in new stack

where it sets the ring timer to 15 seconds.

I don’t necessarily care where the system call is made within the dialplan for this agent extension. I only care that it gets run without affecting the rest of the call.

I’m not looking for the full solution from you guys… just hints as to how to work with the dial plan in a way that doesn’t break/hack FreePBX.


(Lorne Gaetz) #10

There are a few ways, the easiest using Follow Me. Suppose you have extension 1000 that you want to trigger custom code whenever it’s dialed, and you have this dialplan in extensions_custom.conf:

[extension-notify]
exten => _X.,1,Noop(Entering user defined context [extension-notify] in extensions_custom.conf)
; add some more lines here, make sure nothing uses Answer
exten => _X.,n,Hangup

Then create extension 51000 of type custom with this dial string:

local/1000@extension-notify

Then enable Follow Me for extension 1000 and add 51000 as one of the FMFM targets. Bingo you are done. Alternatively instead of using FMFM and a dummy custom extension, you can modify extension 1000 dial string in the advanced tab to include the custom dialplan like this:

SIP/1000&local/1000@extension-notify

Alternatively, you can use the various predial hook contexts that exist for this purpose.


(Cyber Sleuth) #11

If you don’t mind sharing, I’m sure a few people would be interested in what you are doing. Sounds like it could be useful for many projects.


(Albertlauts) #12

This option:

SIP/1000&local/1000@extension-notify

will work nicely!!! Thank you for the suggestion lgaetz!!!


(system) closed #13

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.