strip and add digit before outbound call

Status
Not open for further replies.

Win

Member
Feb 12, 2024
49
2
8
Hi,

Sometimes the user dials with country code (62 or +62) and they might also dial 0, for example: 628112345678 or +628112345678 or 08112345678, question:

How to strip the digits and add 0 as the prefix if they dials with 62 or +62 and add 1 digit 0, so in my case above: if they dial 628112345678 or +628112345678 --> then it would changed to 08112345678.

mine was:

<extension name="cs-622131111111" continue="false" uuid="4420efd3-702e-4aee-bd04-5ae872bf6a18">
<condition field="${user_exists}" expression="false"/>
<condition field="destination_number" expression="^(\d+)$">
<action application="export" data="call_direction=outbound" inline="true"/>
<action application="unset" data="call_timeout"/>
<action application="set" data="hangup_after_bridge=true"/>
<action application="set" data="effective_caller_id_name=${outbound_caller_id_name}"/>
<action application="set" data="effective_caller_id_number=${outbound_caller_id_number}"/>
<action application="set" data="inherit_codec=true"/>
<action application="set" data="ignore_display_updates=true"/>
<action application="set" data="callee_id_number=$1"/>
<action application="set" data="continue_on_fail=1,2,3,6,18,21,27,28,31,34,38,41,42,44,58,88,111,403,501,602,607,809"/>
<action application="bridge" data="sofia/gateway/f6459421-00c3-492a-ad7d-65d6a161ba1d/$1"/>
</condition>
</extension>

anybody can give me suggestion?
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
This regex will work for you:
Code:
^(?:\+?62|0)(\d+)$
This will strip +62 or 62 or 0 returning the rest of the number in $1
All you need to do is add the 0 in front of your $1 in the bridge statement.

This is how the regex works:
^ anchors the beginning of the line.
(?: starts a non-capturing group
The non capturing group has two alternatives \+?62 and 0 (we need to escape the + with the \ because it is a regex special character)
The ? matches the previous character zero or one times, so the plus can be present or not.
) closes the non capturing group.
(\d+) is a capturing group for 1 or more digits, these get captured into $1
$ asserts the end of the line.

I hope that helps.
 
Status
Not open for further replies.