SOLVED There is a way to trigger an external url from Freeswitch?

Status
Not open for further replies.

Nedo

Member
Jun 22, 2020
59
3
8
40
Hi, i wish to trigger an url if from an extension if press a memory key, is possibile? I have read someting on internet about mod curl and lua but i can't understand how it work.

Mi intent is to create a door opener.

Example if i digit a code "101" or similar that i can assign to a memory key, freeswitch touch a url like "http://192.168.x.x/relay/0?turn=on"

Is possible?

Thank You.
 
Last edited:

whut

Member
Dec 23, 2022
228
22
18
Yes it is possible. It will be dependent on which make model a firmware version you are using as each phone would implement it differently. I would start by looking at the phones embedded web server and looking for configuring a key with "Url" type.

Fanvil and Snom both have public address devices that have relay controls Once provisioned with an extension and a little bit of configuration you can simply dial that extension and perhaps a code to turn on/off relay one, two, three, four. This method is simple to set up. I have a PA device that I can call from the outside and locally to control garage doors and lights.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
There are many ways in which you can do this. If using an endpoint, Yealink phones have an "Action URL" feature.

If, as the title of your post suggests, you would like Freeswitch, to call an external URL, then you have these [not limited to] options:

  • Use an .lua script to call the URL.
  • Use bgsystem (mod_dptools) to call an external program to call the URL.
  • Use mod_httapi
  • or possibly the easiest of all, use mod_curl. Link to example below:

https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_curl_3965033
 
  • Like
Reactions: falk

Nedo

Member
Jun 22, 2020
59
3
8
40
Hi, thank you for information!
I have created a dialplan entry like this:

<extension name="Test" continue="false" uuid="afb83470-e31a-4e17-8aea-3ee92d5e4239">
<condition field="destination_number" expression="#*">
<action application="curl" data="http://77.xxx.xxx.xxx:9191/relay/0?turn=on connect-timeout 5"/>
<action application="transfer" data="3001 XML xxx.xxx.cloud"/>
</condition>
</extension>

The freeswitch istance is in cloud so In the router i have redirected incoming wan port 9191 to internal ip of relay at the 80 port and this work perfectly!!!

it would be nice to be able to know if he actually reached the web page for the command and in case of an error make him say another sentence, is possible?
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
it would be nice to be able to know if he actually reached the web page for the command and in case of an error make him say another sentence, is possible?
The curl application sets the variables curl_response_data and curl_response_code, so you can test these variables to decide if any further action is required.
 

Nedo

Member
Jun 22, 2020
59
3
8
40
Ok very thanks!
Now i have wrote this XML and working:

<extension name="Test" continue="false" uuid="afb83470-e31a-4e17-8aea-3ee92d5e4239">
<condition field="destination_number" expression="1919">
<action application="curl" data="http://77.xxx.xxx.xxx:9191/relay/0?turn=on" inline="true"/>
<action application="log" data="INFO Curl response code: ${curl_response_code}"/>

<!-- Controlla se curl_response_code è uguale a 200 -->
<condition field="${curl_response_code}" expression="^200$">
<!-- Esegue l'azione di trasferimento solo se la condizione è vera -->
<action application="transfer" data="3001 XML centralino.con9.cloud"/>
</condition>
</condition>
</extension>

I've tried different approaches to create an else type, I would like if that condition weren't true he would do something else but I couldn't. At the moment, if it is true, the IVR starts, if it is false, it hangs up. I'd like to send it to another IVR saying a sentence in case that statement isn't true. Can you give me a hand please?
 

Nedo

Member
Jun 22, 2020
59
3
8
40
Today i have do some attempts with anti action, now for example this code:

<extension name="Test" continue="false" uuid="afb83470-e31a-4e17-8aea-3ee92d5e4239">
<condition field="destination_number" expression="1919">
<action application="curl" data="http://77.xxx.xxx.xxx:9191/relay/0?turn=on" inline="true"/>
<action application="log" data="INFO Curl response code: ${curl_response_code}"/>

<!-- Controlla se curl_response_code è uguale a 200 -->
<condition field="${curl_response_code}" expression="^200$">
<!-- Esegue l'azione di trasferimento solo se la condizione è vera -->
<action application="transfer" data="3001 XML centralino.con9.cloud"/>
<anti-action application="transfer" data="3002 XML centralino.con9.cloud"/> <----IT GIVE ME THIS OPTION when i call 1919
</condition>
</condition>
</extension>
But the ${curl_response_code} has value 200 i am sure i can see it in log.
Why?
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
I'm not near any of my test boxes right now so I can't test this, but you may need to break your conditions in to a couple of groups, something like this:

Code:
<extension name="Test" continue="false" uuid="afb83470-e31a-4e17-8aea-3ee92d5e4239">
    <condition field="destination_number" expression="1919">
        <action application="curl" data="http://77.xxx.xxx.xxx:9191/relay/0?turn=on" inline="true"/>
        <action application="log" data="INFO Curl response code: ${curl_response_code}"/>
    </condition>
    <condition field="destination_number" expression="1919"/>
    <condition field="${curl_response_code}" expression="^200$">
        <action application="transfer" data="3001 XML centralino.con9.cloud"/>
        <anti-action application="transfer" data="3002 XML centralino.con9.cloud"/>
    </condition>
</extension>
 

Nedo

Member
Jun 22, 2020
59
3
8
40
I'm not near any of my test boxes right now so I can't test this, but you may need to break your conditions in to a couple of groups, something like this:

Code:
<extension name="Test" continue="false" uuid="afb83470-e31a-4e17-8aea-3ee92d5e4239">
    <condition field="destination_number" expression="1919">
        <action application="curl" data="http://77.xxx.xxx.xxx:9191/relay/0?turn=on" inline="true"/>
        <action application="log" data="INFO Curl response code: ${curl_response_code}"/>
    </condition>
    <condition field="destination_number" expression="1919"/>
    <condition field="${curl_response_code}" expression="^200$">
        <action application="transfer" data="3001 XML centralino.con9.cloud"/>
        <anti-action application="transfer" data="3002 XML centralino.con9.cloud"/>
    </condition>
</extension>


It work like a charm!!! I really thank you so much!
 
  • Like
Reactions: Adrian Fretwell
Status
Not open for further replies.