Send HTTP command when extension is dialed

Looking to have an HTTP trigger command sent to a door access controller when an extension is called then play a message over the paging system. In this situation it will be a lock down for a school, locking all the mag locks on their doors. I have created a custom extension in extensions_custom.conf [lockdown-lock-doors] then made a customer extension 7777 and set the Dial to “local/s@lockdown-lock-doors”. In extensions_custom.conf I have the following lines of code.

[lockdown-lock-doors]
;Lockdown feature code and script
exten => s,1,Set(result=${CURL(- user:password http://192.168.xxx.xxx/vapix/doorcontrol?format=simple&action=LockDownDoor&Token=Axis-accc8ee11020:1566846890.452790000)})
;exten => s,n,Dial(Sip/12100))
;exten => s,n,Playback(custom/Lockdown)
;exten => s,n,Hangup()

I removed the username and password and masked the IP for security.

I haven’t even worked on the message playback which is why its commented out. I’m looking to get the door lockdown working first.

Start off by staying within the Path designed for this.

Make s,1 of your context a NoOp(“entering my thing”). That way you can see it in the log when you test.

Make your custom context, but then create a custom destination that calls it.

Then call the custom destination with a misc application. I used a * code but you can just use 7777.

Call files are handy if you want to playback an announcement to a called party or execute additional dialplan after it answers.
You can try something like this:

[lockdown-lock-doors]
exten => s,1,CURL(http://192.168.xxx.xxx/vapix/doorcontrol?format=simple&action=LockDownDoor&Token=Axis-accc8ee11020:1566846890.452790000)
 same => n,System(echo -e "Channel: Local/12100@from-internal\\nContext: announcement-lockdown\\nExtension: s" > /tmp/file.call) 
 same => n,System(mv /tmp/file.call /var/spool/asterisk/outgoing/)

[announcement-lockdown]
exten => s,1,Playback(custom/Lockdown)
 same => n,Hangup()

You can also reference the playback application in the call file itself without the extra announcement-lockdown context, but in above example you could do a bit more dialplan if you wanted.

1 Like

Try passing user/pass and GET args like this:

exten => s,1,Set(result=${CURL(http://username:[email protected]/vapix/doorcontrol,format=simple,action=LockDownDoor,Token=Axis-accc8ee11020:1566846890.452790000)})

mwdt = might work, didn’t test

Thanks all for the ideas. Igaetz you have the correct string there. Unfortunately the username and password keep getting stripped off of the string and it keeps returning looking for the username and password.

A thing I wrote a while back to do this kind of thing. It could be easily adapted

Finally figured it out after lots of research and figured I would post incase anyone else runs into the issue. The exact line of code with username:password and IP address replaced is:

exten => s,1,Set(result=${SHELL(curl --digest -v -u username:password -G “http://192.168.xxx.xxx/vapix/doorcontrol?format=simple&action=LockDownDoor&Token=Axis-accc8ee11020:1566846890.452790000”)}) ;Back Door

After doing lots of wiresharking an other testing/log reading it was the was it was pulling the username and password out of the string and not passing it.

Now to try and figure out/understand call files. Never used them before and that’s my next issue

The dialplan application Originate() can do the announcement within the dialplan so that you don’t have to generate a call file.

It would look something like…

same => n,Originate(Local/pagingnumber@from-internal,app,Playback,name-of-soundfile)

Similar to the Perl mantra, “there’s more than one way to do it.”

@billsimon That worked perfectly

1 Like

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