The callflow I want to build:
- Play Welcome Prompt (5 seconds)
- Do a CURL request to an API based on the callerId number
- Based on the response of step 2, play another prompt or hangup the call
Problem
The Curl request may take upto 3 seconds of delay, I want to play the prompt and want to do a CURL request simultaneously, I have tried MOH, but the problem with MOH is that it stops playing the prompt when the CURL response is recieved. Actual callflow is:
exten => 1002,1,Progress()
exten => 1002,n,StartMusicOnHold(T1)
exten => 1002,n,Set(CURL_RESULT=${CURL(http://192.168.0.38/test.php?aparty=${CALLERID(num)})})
exten => 1002,n,NoOp(isSubscriber:${CURL_RESULT})
exten => 1002,n,GotoIf($["${CURL_RESULT}"!="0"]?lbl_call_hangup:)
exten => 1002,n,StopMusicOnHold(T1)
exten => 1002,n,Playback(welcome)
exten => 1002,n,Read(DTMF,,0,n,1,10)
exten => 1002,n,Hangup
What I want is to playing complete prompt and while playing the prompt, do the curl request at the backend. There is another solution we have tried which is to write a wrapper for this API call which returns immediately and another API call to get the result.
Here is what we built:
- Do CURL request to wrapper which returns immediately
- Play Welcome Prompt
- Do CURL request to get the response of the initial request done in step 1
- -do the rest of the things-
But the problem in this callflow is that the wrapper has to keep the request/response pair in memory, have to do alot of house keeping in case the call drops during step 2 etc.
Question
So is there a way in the dialplan to achieve playing of prompt and doing a curl request in the meanwhile.
PS: Using astersik 13.18.3
Can recommend you read book, for example ORelly's "Asterisk the future of telephony"
Possible solutions:
1) use dial and Local channel with 'm' param for hold music. In local context where you dial do curl
2) use AGI and "SET MUSIC ON/OFF"
3) use curl in background thread.
4) use Background app.
BTW, if call drop while dooing curl request anyway you get unpredictable result. You have care about that yourself(transaction,confirmation etc)