0

I have following dialplan:

       <extension name="public_did">
            <condition field="destination_number" expression="^({{ $externalNumber }})$">
                <action application="sleep" data="1000"/>
                <action application="play_and_get_digits" data="9 9 3 5000 # welcome.wav error.wav ${confid}" />
                <action application="event" data="Event-App-Type=READ-EXECUTED,Read-Result=${read_result}"/>
                <action application="log" data="Read-Result=${read_result}"/>
                <action application="play_and_get_digits" data="5 5 3 5000 # pin.wav pin-error.wav ${pin}" />
                <action application="curl" data="https://example.com/do-freeswitch-dialin?id=${confid}&pin=${pin}" inline="true"/>
                <condition field="${curl_response_code}" expression="500">
                    <anti-action application="set" data="conf=${curl_response_data}"/>
                    <action application="speak" data="There was an error! Please try again later!" />
                    <action application="hangup" data="500"/>
                </condition>
                <action application="conference" data="${conf}{{ '@' }}default"/>
            </condition>
        </extension>

The problem here is that the curl gets executed before the user enters his credentials via DTFM. What is the correct way to do it? IN this solution it is important to do the cURL request before joining.

Maxi
  • 415
  • 4
  • 24
  • 1
    Can you put in some logs? I'm not sure but this seems very strange and "play and get digits" should be executed first. I do not remember, but I made similar stuff several times some time ago and it was working. In any case I would recommend to use Lua for something like this. – os11k Aug 05 '20 at 08:44
  • Here you go @os11k: https://pastebin.com/DxG7svi1 - AS you see it does the CURL request right away after answering, not after entering the DTMF. Therefore I receive for both NULL on my webserver – Maxi Aug 05 '20 at 09:37
  • Do you missed `` in your first example and that why it didn't work as expected? – os11k Aug 05 '20 at 11:03
  • Thats possible yes! – Maxi Aug 05 '20 at 11:07

1 Answers1

0

I managed it doing by LUA. Here my XML config:

<extension name="public_did">
    <condition field="destination_number" expression="^(12345)$">
        <action application="answer" />
        <action application="set" data="dtmf_type=rfc2833"/>
        <action application="start_dtmf" />
        <action application="lua" data="basic.lua"/>
    </condition>
</extension>

And in /usr/share/freeswitch/scripts/basic.lua

session:sleep(500)
session:execute("playback", "ivr/ivr-douche_telecom.wav");

digits = session:playAndGetDigits(4, 10, 3, 3000, "#", "ivr/ivr-please_enter_the_number_where_we_can_reach_you.wav", "ivr/ivr-invalid_extension_try_again.wav", "\\d+", "digits_received", 1000,
"5000 XML default");

session:execute("playback", "ivr/ivr-thank_you.wav");

api = freeswitch.API();
get_response = api:execute("curl", "https://example/freeswitch-dialin?id=" .. digits);
api:execute("log", get_response);
api:execute("log", digits);

Works for me. Important was to set the dtmf_type so that incomming calls from a SIP trunk get answered as well!

Maxi
  • 415
  • 4
  • 24