Working on a user agent for the browser. Now I want to pre-occupy the number plus the dial plan READ input. The call looks like this: sip:31612345678,123,456@ip:5061
Where 31612345678 is the extension, 123 is the pin, and 456 is the ref.
; welcome
; check if this is an variable or none variable call
; a variable call uses the wallet, a none variable calls doesn't
same => n,Verbose(Do we need pin validation cause its a variable call\?);
same => n,GotoIf($[${ctbVariableTpm}=1]?ctbVariablePinValidation,1,1:ctbInboundCallStart,1,1)
[ctbVariablePinValidation]
exten => 1,1,Verbose(Pin validation)
same => n,Read(pin,/etc/asterisk/dialplans/chattabai/prompts/enterPinCode,${ctbPinLength})
same => n,Set(ctbJsonResult=${SHELL(curl -s -k '${ctbAppHost}/wp-json/ctb/v1/wallet/pin/validate?pin=${pin}&authenticationHash=${ctbAuthenticationHash}')})
same => n,Set(ctbJsonStatus=${SHELL(echo '${ctbJsonResult}' | jq '.status' | tr -d '\n"')})
same => n,GotoIf($[${ctbJsonStatus}=1]?ctbVariablePinSuccess,1,1:ctbVariablePinFailed,1,1)
[ctbVariablePinSuccess]
exten => 1,1,Verbose(Pin success)
same => n,Set(ctbVisitorWalletId=${SHELL(echo '${ctbJsonResult}' | jq '.wallet.id' | tr -d '\n"')})
same => n,Set(ctbVisitorUserId=${SHELL(echo '${ctbJsonResult}' | jq '.wallet.userId' | tr -d '\n"')})
same => n,Set(ctbVisitorTokens=${SHELL(echo '${ctbJsonResult}' | jq '.wallet.tokens' | tr -d '\n"')})
same => n,Goto(ctbVariableInboundCallStart,1,1)
[ctbVariableInboundCallStart]
exten => 1,1,Verbose(Creating variable inbound call)
same => n,Set(ctbJsonResult=${SHELL(curl -s -k '${ctbAppHost}/wp-json/ctb/v1/session/call/asterisk/create?walletId=${ctbVisitorWalletId}&userId=&dialedNumber=${CALLERID(dnid)}&inboundNumber=${CALLERID(num)}&outboundNumber=&type=inbound&dialStatus=&channelId=${CDR(uniqueid)}&context=${CONTEXT}&authenticationHash=${ctbAuthenticationHash}')})
same => n,Set(ctbSessionId=${SHELL(echo '${ctbJsonResult}' | jq '.data.sessionId' | tr -d '\n"')})
same => n,Set(ctbSessionStatus=${SHELL(echo '${ctbJsonResult}' | jq '.status' | tr -d '\n"')})
same => n,GotoIf($[${ctbSessionStatus}=1]?ctbVariableRefValidation,1,1:ctbVariableInboundCallStartFailed,1,1)
[ctbVariableRefValidation]
exten => 1,1,Verbose(Variable ref validation)
same => n,Read(ref,/etc/asterisk/dialplans/chattabai/prompts/enterReference,${ctbRefLength})
same => n,Set(ctbJsonResult=${SHELL(curl -s -k '${ctbAppHost}/wp-json/ctb/v1/user/ref/validate?ref=${ref}&authenticationHash=${ctbAuthenticationHash}')})
same => n,Set(ctbSessionStatus=${SHELL(echo '${ctbJsonResult}' | jq '.status' | tr -d '\n"')})
same => n,GotoIf($[${ctbSessionStatus}=1]?ctbVariableRefSuccess,1,1:ctbVariableRefFailed,1,1)
To make a a bit more clear, this is how it works now with JsSIP. Using setTimeout((), 2000) and setTimeout((), 4000) it will send the pin and the ref. Which works, but its a “dirty hack” and would rather have it the dial plan.
// handle start web phone call
startWebPhoneCall(data) {
// register callbacks to desired call events
let eventHandlers = {
'progress': function (e) {
console.log('call is in progress');
},
'failed': function (e) {
console.log('call failed with cause: ' + e.cause);
},
'ended': function (e) {
console.log('call ended with cause: ' + e.cause);
},
'confirmed': function (e) {
console.log('call confirmed');
},
};
let options = {
'eventHandlers': eventHandlers,
'mediaConstraints': {'audio': true},
'stun_servers': ctbMethod.stunTurn.url + ':' + ctbMethod.stunTurn.port
};
// make the call
let call = webPhoneUserAgent.call('sip:'+ data.getAttribute('data-web-phone-number') + '@'+ ctbMethod.asterisk.realm + ':' + ctbMethod.asterisk.port, options);
if (call) {
call.connection.addEventListener('addstream', (e) => {
let audio = document.createElement('audio');
audio.srcObject = e.stream;
audio.play();
});
// wait 2 seconds before entering the pincode
setTimeout(() => {
call.sendDTMF(ctbMethod.wallet.pin);
}, 2000);
// wait 2 seconds before entering the reference
setTimeout(() => {
call.sendDTMF(data.getAttribute('data-ref'));
}, 4000);
}
Any suggestions how to automate this input in the dial plan.