I am trying to use FreesSWITCH with the Mizu WebRTC to SIP client. If the called user is registered to FreesSWITCH than the call should be routed to the user. Otherwise the call should be routed to outbound SIP server.
The problem is that I am unable to find out from the FreesSWITCH dialplan if user is currently registered or not. I have the following in the default dialplan:
<!-- If the user doesn't exist, forward to outbound SIP -->
<extension name="check_user">
<condition field="${user_exists(id ${destination_number} $${domain})}" expression="false">
<action application="bridge" data="sofia/gateway/asterisk/${destination_number}"/>
</condition>
</extension>
<!-- If the user is registered, forward the call to them -->
<extension name="check_user_registered">
<condition field="${sofia_contact(profile/${destination_number}@$${domain})}" expression="(.+)">
<action application="bridge" data="$1" />
</condition>
</extension>
<!-- Otherwise forward to outbound SIP -->
<extension name="outbound">
<condition field="destination_number" expression="^.*$">
<action application="bridge" data="sofia/gateway/asterisk/${destination_number}"/>
</condition>
</extension>
However the "check_user_registered" rule seems to be passed even if the user is not actually registered from the Webphone, so the FreesSWITCH will go to send the call to the user, but then finds out that it is not registered and the call fails. (I think that WebRTC doesn't matter here, this would be the same for SIP to SIP calls).This is the relevant log:
Dialplan: sofia/internal/2233@81.12.74.77 Regex (PASS) [check_user_registered] ${sofia_contact(profile/${destination_number}@rtc.mizu-voip.com)}(error/user_not_registered) =~ /(.+)/ break=on-false
Dialplan: sofia/internal/2233@81.12.74.77 Action bridge(error/user_not_registered)
Freeswitch hangup with 480 Temporarily Unavailable / USER_NOT_REGISTERED
Do you know any reliable way to query from FreesSWITCH dialplan the user registered status?
Use sofia_contact
to know whether the called person is registered or not.
For example:
sofia_contact 1001
return this to me
sofia/internal/sip:1001@myip_address:52573;rinstance=a1b0a9cfddc6a8c3;transport=TCP
sofia_contact 1002
error/user_not_registered
Another option is to store the registered user into database and using odbc query fetch the result and compare.(That will be a brilliant idea)