Extract contact number from sms

Post your questions and help other users.

Moderator: Martin

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Extract contact number from sms

Post by anuraag » 24 Jan 2015 02:22

Hi
I daily receive sms which contains a mobile number(10 digits), amount(3 to 4 digits plus two decimals) and some text.
I want to extract that mobile number and send it.
Please help. I know it can be done by scripts but i don't know how.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Extract contact number from sms

Post by Martin » 24 Jan 2015 13:10

Hi,

There are different ways to extract text from a variable but in this case it sounds like a regular expressions with one or two capturing groups could be used.
Please check out this page for a few examples.
Especially the example Find the content of the groups in a regular expression might be useful.

I can give you a more tangible example if you post the text of an SMS.

Regards,
Martin

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Extract contact number from sms

Post by anuraag » 24 Jan 2015 16:35

Here is two types message which I will receive

"2060.00 of eTopUp has been credited to 7873472973. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437."

"Retailer 7873472973 balance for products: etopup: 3328.08”

Then I need to send following SMS
"Msmart 7873472973"

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Extract contact number from sms

Post by anuraag » 26 Jan 2015 11:11

I have successfully created script

value = "2060.00 of eTopUp has been credited to 7873472973. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437.";
list = newList();
result = matches(value, '.*(\\d{10}).*', list);
contact = getElement(list, 1)


Is it possible to send sms like this
Msmart {random number from contact group}

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Extract contact number from sms

Post by TheBrain1984 » 26 Jan 2015 13:30

You should make something like this:

Code: Select all

l_list = length(contact_group);                                             //l_list contains now the number of elements in contact
index_notrounded = (l_list -1) * random();                              //the not rounded index of the element you will use
index_rounded = round(index_notrounded);
random_contact = getElement(contact_group, index_rounded); //finally a random contact out of the contact_group

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Extract contact number from sms

Post by anuraag » 26 Jan 2015 14:38

Thanks for replying but that didn't work

l_list = length(contact_group)
Returns length of contact_group

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Extract contact number from sms

Post by TheBrain1984 » 26 Jan 2015 14:39

anuraag wrote:Thanks for replying but that didn't work

l_list = length(contact_group)
Returns length of contact_group
is contact_group of type list?

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Extract contact number from sms

Post by anuraag » 26 Jan 2015 15:01

Nope its number ex. 1234567890

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Extract contact number from sms

Post by TheBrain1984 » 26 Jan 2015 15:37

How I understood the problem:

You have a lot of values and every value you'll save in contact_group. So if you get the values

value = "2060.00 of eTopUp has been credited to 7873472973. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437.";
value = "2060.00 of eTopUp has been credited to 7873472974. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437.";
value = "2060.00 of eTopUp has been credited to 7873472975. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437.";
value = "2060.00 of eTopUp has been credited to 7873472976. New Balance is eTopUp: 1560.00 . Please collect Rs 1,998.20 from retailer . No.is MAG/1501/I008437.";

you'll have the contacts 7873472973,7873472974,7873472975,7873472976. Correct?

If I understood it correctly than you have to make a list of numbers (or list of text) (in my post it was contact_group, maybe you'll need a global_variable, because local will be deleted after the end of a flow) with these values. With this variable it schould work.

If your problem is another one then I didn't get it yet.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Extract contact number from sms

Post by anuraag » 26 Jan 2015 15:45

Well you totally got wrong.

I want to send a message "msmart {contact}" to a number
{contact} = any random phone number from my phone book from a contact group(co-workers)

Want to if its possible

Post Reply