0
votes

Noob here, I need help with a simple script (php or XML) that strips a portion of the inbound callerid, in Twiml then forwards that call to the original e164 number dialed. Eg. call comes from [email protected]:5061 - PHP/xml script strips everything off but the e164 number and then twiml that number. So the resulting outbound leg would simply be +16045551212.

Since Twilio supports webhooks, we should be able to take in the number, strip the unwanted bit and return a sanitized number for the outbound leg.

I have recording working and if I place a e164 number in statically, it works fine. I am just having trouble with stripping the unwanted but off the sip uri and telling the system to dial that new number.

I tried using {{From}} but that includes the entire from callerid, including the unwanted sip uri bits.

Twiml webhook I am calling from system...

<Response>
 <Say> This call will be recorded for quality assurance purposes. Please standby.</Say>
 <Dial record="record-from-ringing-dual" callerId="+1xxxxxxxxx">
 <Number>+1xxxxxxxx
 </Number>
</Dial> 
</Response>

I would be grateful for any help here!

1

1 Answers

0
votes

Have you looked at the {#e164} function of TwiML Bins?

How to use templates with TwiML Bins

Execute Built-in Functions The last feature to share is access to built-in functions. The first such built-in function to ship makes it easy to pull a phone number out of parameters and reformat as E.164. This is very helpful when bridging SIP endpoints such as a Polycom phone with the PSTN world.

For example, let's say a Voice call comes in to a SIP Interface with a To value of sip:[email protected]. Since the e.164 phone number is embedded in the SIP endpoint's address, you can use the new built-in e164 function to pull out this phone number and craft the proper TwiML to forward the call:

<Response>
  <Dial>{{#e164}}{{To}}{{/e164}}</Dial>
</Response>