Studio - Split Regex result - {trigger.call.From}}

412 views
Skip to first unread message

Marcelo Lara

unread,
Mar 18, 2021, 3:51:05 PM3/18/21
to Twilio Functions
Hello im using Studio and when i receive a call i send to Split to gather the number who is calling {{trigger.call.From}}, since im from Brazil the number has + the number of the country, the nunber of the city and the number if its mobile or other phone number.
Mobile number: +5511981360101
Phone number: +551131055000

I nee using regex to get the result without the +55 and after that, transform in a spcecific way to use in a the Studio (Make HTTP Request)
The format im receiving is: 
I need
1.1) 11 98136.0101
and 
i need
2.1) 11 3105.5000

After this done i need to use Make HTTP Request in 
3) Request Method: GET
Request http://marcelol-rest.vistahost.com.br/clientes/listar?key=XXXXXXXXXXXXXXXXXX&showtotal=1&pesquisa={"fields":["Codigo","Nome","EmailResidencial","Celular","DataCadastro"],"filter":{"Celular":"11 98136.0101"},"paginacao":{"pagina":1,"quantidade":50}}
Header:
Name: Accept
Value: application/json

For some reason this isnt working.
Im unable to parse the phone number using REGEX and my URL Studio says: "url must be a valid URL or liquid expression"

Thanks
Message has been deleted

Marcelo Lara

unread,
Mar 18, 2021, 3:53:57 PM3/18/21
to Twilio Functions
I tried to use this Function but still didnt work

exports.handler = function(context, event, callback) {

let regexp = /[0-9]{10}/;
  var str =  event.Body;  
  var matches_array = str.match(regexp);
  console.log(event.Body)
  if(matches_array){
  var numer = matches_array[0];
  callback(null, {"nummer": numer});
   }
   else{
        callback(null, {"nummer": "no number found"});
   }

};


akl...@twilio.com

unread,
Mar 18, 2021, 4:24:29 PM3/18/21
to Twilio Functions
It looks like you need to encode the URL query parameters in the HTTP Request Widget URL, like

key=XXXXXXXXXXXXXXXXXX&showtotal=1&pesquisa=%7B%22fields%22:%5B%22Codigo%22,%22Nome%22,%22EmailResidencial%22,%22Celular%22,%22DataCadastro%22%5D,%22filter%22:%7B%22Celular%22:%2211%2098136.0101%22%7D,%22paginacao%22:%7B%22pagina%22:1,%22quantidade%22:50%7D%7D

Studio uses Liquid Syntax, and there is a function: 
  • url_encode - url encode a string

Marcelo Lara

unread,
Mar 18, 2021, 7:14:56 PM3/18/21
to Twilio Functions
Thanks I will trie to do like you said.
I tried before like this:

$dados = array(
'fields' => array( 'Nome', 'EmailResidencial', 'Codigo', 'Celular')
);
'filter' => array(
'Celular' => '11 98136.0101')
);
$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //Informe sua chave aqui
$postFields = json_encode( $dados );
$url .= '&pesquisa=' . $postFields;
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER , array( 'Accept: application/json' ) );
$result = curl_exec( $ch );
$result = json_decode( $result, true );
print_r( $result );

Marcelo Lara

unread,
Mar 18, 2021, 8:16:03 PM3/18/21
to Twilio Functions
Hello it worked in parts you advice. but it saids i need to add:
Header \"Accept: application/json\""

where do i insert this and how?


Em quinta-feira, 18 de março de 2021 às 17:24:29 UTC-3, akl...@twilio.com escreveu:

Alan

unread,
Mar 19, 2021, 8:07:50 AM3/19/21
to Twilio Functions
You will not have control over HTTP headers from the Twilio Studio HTTP Request widget. You can use the Studio Run Function widget and follow/extend the Twilio Function Examples, Make a Read Request to an External API and Make a Write Request to an External API using JSON, to add any necessary headers to your HTTP Request.

Marcelo Lara Smith de Vascconcellos

unread,
Mar 19, 2021, 12:14:59 PM3/19/21
to Alan, Twilio Functions

Do you have some example and how can i do this because i need to scale my business using Twilio


If you read all my comment down there i wrote all the code, its possible for you to write for me how i do it please


Thanks

---

Grato

Marcelo Lara Smith de Vasconcellos

Marcelo Lara Negócios Imobiliários

(11) 98136-5501

(11) 3105-6300

www.marcelolara.com.br

--
You received this message because you are subscribed to a topic in the Google Groups "Twilio Functions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/twilio-functions/eS4LKEmQWAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to twilio-functio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/twilio-functions/66c4cbe8-5f7a-4ce8-913c-1e002fe54e36n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages