Blocking whole area codes of numbers except one or two

Wjbell

Member
I've got a macro made to wear I can block a whole area code from incoming calls. Have the macro constructed 2 detect it is from an area code with wildcards after it, pick up the call, wait three seconds and then hang up the call. But I have certain area codes that I want to block the whole area code except allow a couple few numbers. Is that possible? I don't know how to add that into the action. Any help would be much appreciated thanks
 

tanutanu

Well-known member
I've got a macro made to wear I can block a whole area code from incoming calls. Have the macro constructed 2 detect it is from an area code with wildcards after it, pick up the call, wait three seconds and then hang up the call. But I have certain area codes that I want to block the whole area code except allow a couple few numbers. Is that possible? I don't know how to add that into the action. Any help would be much appreciated thanks
Try like this if you are based in the US.
 

Attachments

  • Screenshot_20211105-012131~2.png
    Screenshot_20211105-012131~2.png
    139.5 KB · Views: 64
  • Screenshot_20211105-012000~2.png
    Screenshot_20211105-012000~2.png
    76.3 KB · Views: 59

Wjbell

Member
Thank you. But and totally new to macrodroid. I used to program in Pearl on Linux and windows so I'm familiar with regular expressions and things like that but as far as adding this to my action in macrodroid I have no idea how to do this. Can somebody help me walk me through how to add these rules where to input the variables excetera?
 

Wjbell

Member
Thank you. But and totally new to macrodroid. I used to program in Pearl on Linux and windows so I'm familiar with regular expressions and things like that but as far as adding this to my action in macrodroid I have no idea how to do this. Can somebody help me walk me through how to add these rules where to input the variables excetera?
Perl
 

Wjbell

Member
Try like this if you are based in the US.
Also, I want to do this per area code. For example, I don't want to implement this for all calls, I just want to implemented for the 209 area code. I don't want to have to whitelist every number I want to come through.

If there's a better way to do this, say create a blacklist of numbers and make one general macro that will screen all calls and check a blacklist and if the numbers in their reject the call otherwise they're automatically whitelisted to go through. Sorry for asking so many questions but this is all new to me I'm just trying to set up a call filter to get rid of robocalls.
 

Wjbell

Member
Also, I want to do this per area code. For example, I don't want to implement this for all calls, I just want to implemented for the 209 area code. I don't want to have to whitelist every number I want to come through.

If there's a better way to do this, say create a blacklist of numbers and make one general macro that will screen all calls and check a blacklist and if the numbers in their reject the call otherwise they're automatically whitelisted to go through. Sorry for asking so many questions but this is all new to me I'm just trying to set up a call filter to get rid of robocalls.
One last thing, I would like the blacklist to be able to contain whole area codes or specific numbers or numbers with wildcards.
 

tanutanu

Well-known member
The regexp of MD is based on Java but very similar to Perl.
The difference is that MD magic text is extracted before passing to regexp. So, the string variable "rejectPattern" is replaced to a part of regexp. "123|456|789" is just an example of area codes
it means matching pattern as 123|456|789[0-9]{7}
oops with group might be better, do like (123|456|788). If you want to exclude just an area code, simply assign in the variable 3 digits only.
 
Last edited:

tanutanu

Well-known member
The following "[0-9]{7}" means 7 digits as you know. So whole pattern matches to caller id starting 123 or 456 or 788 area code + 7 digits number.
 

Wjbell

Member
Okay thank you. I don't know, I'm going to have to let this soak in a while. It's just the different places in MD do you enter certain things in and I have to familiarize myself with. With perl I just opened up a notepad and started writing. *shrug*
 

tanutanu

Well-known member
Also, I want to do this per area code. For example, I don't want to implement this for all calls, I just want to implemented for the 209 area code. I don't want to have to whitelist every number I want to come through.
It would be done by my example.
If there's a better way to do this, say create a blacklist of numbers and make one general macro that will screen all calls and check a blacklist and if the numbers in their reject the call otherwise they're automatically whitelisted to go through. Sorry for asking so many questions but this is all new to me I'm just trying to set up a call filter to get rid of robocalls.
It is impossible because only you know who while or black is. You can prepare pre-defined while list filter as the example.
It is just a string variable but works good enough to Individual phone number. And I don't think so annoying for 10 to 20 exceptions.
 
Last edited:

Wjbell

Member
Try like this if you are based in the US.
Okay, back to my original thread on this. I've looked and looked and I can't find out how to get to some of these functions on the screenshot that you provided. I want to ask a huge favor. If you can make the macro up and send it to me somehow to where I can click on it and install it then I would have a reference of how to get to certain things. I'm kind of in the dark on this macrodroid thing and I tend to learn better if I have a working example that I can dissect. If you could do that for me it would be much appreciated and I can adjust it as needed.
 

tanutanu

Well-known member
Okay, back to my original thread on this. I've looked and looked and I can't find out how to get to some of these functions on the screenshot that you provided. I want to ask a huge favor. If you can make the macro up and send it to me somehow to where I can click on it and install it then I would have a reference of how to get to certain things. I'm kind of in the dark on this macrodroid thing and I tend to learn better if I have a working example that I can dissect. If you could do that for me it would be much appreciated and I can adjust it as needed.
Refer the example on #2 please.
It simply exit when the caller id matched the white list what defined as a variable. Then check the caller id and reject if matched the denial case.
it works even when you add another actions inside the if clause and add extra eleseif clauses.

This moment, you want to refer your contacts and accept their calls, in addition reject calls with +1 national code. All you have to do is that just adding one more trigger for your contacts and actions for it, add if nest for checking existing trigger and modify the condition of the elseif clause.

The priority of the actions is that;
1. [ADD]Exit to accept contacts with the constraint when the trigger fire for it,
2. Exit to accept white listed people,
3. [MODIFY]Reject some area code with/without national code+1.

To realize #1, I recommend you to use the plugin ContactTask instead if you want to check both contact name strings and their caller ids, and/or to use the contacts' labeling feature.

If the modified macro doesn't work, let me see your macro and system log when it is running, taking a screenshot or capturing via "Share macro as image" on the upper right corner "..." menu.
I had never seen yours, so I wonder how much you got coding in MD. I heard you had experiences to make script codes, so I believe you can do it basically:)
I think starting with your macro is much quicker and easier to get the difference if it has just few mistakes.
For me, it is a little annoying to work, just "made for you." I can introduce my macro on the store as an example, but doesn't recommend to use for the simple case. It has so many features but It's a useless "chimera"🙃
 

Wjbell

Member
Okay thank you for taking the time to explain. My macro is just listing every single area code that I want to block with a wild card after the area code. So I have to write a separate macro for each area code and I'm getting more and more area codes that I have to block. My other problem is I don't know how how to add if slash or clauses that can contain wildcards or list partial numbers with an area code and the wild card. So I'm basically lost. I suppose I'll just have to write a separate macro for each area code that I want to block because I don't have enough experience with macrodroid to figure this out.
 

tanutanu

Well-known member
Okay thank you for taking the time to explain. My macro is just listing every single area code that I want to block with a wild card after the area code. So I have to write a separate macro for each area code and I'm getting more and more area codes that I have to block. My other problem is I don't know how how to add if slash or clauses that can contain wildcards or list partial numbers with an area code and the wild card. So I'm basically lost. I suppose I'll just have to write a separate macro for each area code that I want to block because I don't have enough experience with macrodroid to figure this out.
Sorry, I don't imagine why your if condition in your macro don't work with multi area codes.
Did you try the regexp, "(123|456|789)[0-9]{7}"?
I put the digits of are codes into a variable to make it easy to edit.
Just adding +1, you have 2 options. One is putting extra condition into the if condition as one of the element for condition test. The other is modifying the regexp to accept it.

Alternatively, you can use Perl on Termux. However, it doesn't seem to support call rejecting or contacts access unfortunately. So you have to write a wrapper macro if coding with Perl for the text manipulation on Termux.
I think It is more complicated but might be considerable option for you:unsure:
 

Wjbell

Member
Sorry, I don't imagine why your if condition in your macro don't work with multi area codes.
Did you try the regexp, "(123|456|789)[0-9]{7}"?
I put the digits of are codes into a variable to make it easy to edit.
Just adding +1, you have 2 options. One is putting extra condition into the if condition as one of the element for condition test. The other is modifying the regexp to accept it.

Alternatively, you can use Perl on Termux. However, it doesn't seem to support call rejecting or contacts access unfortunately. So you have to write a wrapper macro if coding with Perl for the text manipulation on Termux.
I think It is more complicated but might be considerable option for you:unsure:
Screenshot_20211120-120257.png
Okay this is what I have. I answered in the area codes that I want to exclude from this rule using your latest example. Before I would just enter in one area code that I wanted to exclude and the macro would work perfectly. Now I added the plus one in front of each area code I don't know if that's right or not. And I also replace the 7 with a 9 to allow for the +1. I don't know if I modified it right. So if I make this macro was just one area code like my own area code then when I call from my phone on my area code it won't trigger this macro. But if I make a call from any other area code it will trigger the macro and work perfectly. So am I even close by using what I'm showing here to add multiple area codes?
 

tanutanu

Well-known member
View attachment 1624
Okay this is what I have. I answered in the area codes that I want to exclude from this rule using your latest example. Before I would just enter in one area code that I wanted to exclude and the macro would work perfectly. Now I added the plus one in front of each area code I don't know if that's right or not. And I also replace the 7 with a 9 to allow for the +1. I don't know if I modified it right. So if I make this macro was just one area code like my own area code then when I call from my phone on my area code it won't trigger this macro. But if I make a call from any other area code it will trigger the macro and work perfectly. So am I even close by using what I'm showing here to add multiple area codes?
Well, describing in regexp, the last 7 in the {} curly brackets means the length of the defined character class in the [] square brackets. So it matches 7 digits caller id after area code as I explained on the comment #8. It doesn't need to change at all.
And you have to escape "+" adding "\". Furthermore, the national code doesn't need grouping in the () round brackets.

So it should be "\+1(916|831)[0-9]{7}". If you want to contain the without +1 case, "(\+1|)(916|831)[0-9]{7}" might be better.
Mind a part of expression can replace with a string variable value, i.e. [lv=val] as the screenshot of comment #2. It doesn't need to escape. MD replaces it before regexp matching.
 

Wjbell

Member
Well, describing in regexp, the last 7 in the {} curly brackets means the length of the defined character class in the [] square brackets. So it matches 7 digits caller id after area code as I explained on the comment #8. It doesn't need to change at all.
And you have to escape "+" adding "\". Furthermore, the national code doesn't need grouping in the () round brackets.

So it should be "\+1(916|831)[0-9]{7}". If you want to contain the without +1 case, "(\+1|)(916|831)[0-9]{7}" might be better.
Mind a part of expression can replace with a string variable value, i.e. [lv=val] as the screenshot of comment #2. It doesn't need to escape. MD replaces it before regexp matching.
Screenshot_20211120-133752.png
Okay I did it both ways that you showed and it's still not working. It's running both area codes checking if either one is in the incoming call number. So the 916 passes, but the 831 doesn't pass so it triggers the macro to run thus blocking my call from a 916 phone. Sorry I'm not getting this but I'm thankful for your help. I'm thinking that there's no easy way to do this just dissecting the number in the trigger. It seems like it needs an if/else Klaus in the trigger somewhere. But I can't figure out where to put it in. For instance, if it matches 916, exit the macro. Or else, if it matches 831, exit the macro. And it would run this until it finds a match. Then it would run the macro. If there was no matches at all then the call would be able to come through.
 

tanutanu

Well-known member
View attachment 1625
Okay I did it both ways that you showed and it's still not working. It's running both area codes checking if either one is in the incoming call number. So the 916 passes, but the 831 doesn't pass so it triggers the macro to run thus blocking my call from a 916 phone. Sorry I'm not getting this but I'm thankful for your help. I'm thinking that there's no easy way to do this just dissecting the number in the trigger. It seems like it needs an if/else Klaus in the trigger somewhere. But I can't figure out where to put it in. For instance, if it matches 916, exit the macro. Or else, if it matches 831, exit the macro. And it would run this until it finds a match. Then it would run the macro. If there was no matches at all then the call would be able to come through.
Did you check the system log?
I don't think one of them has national code +1. It is none of the problem of MD itself, just the regexp and your caller id string.
The expression is absolutely correct, so you got an unexpected caller id. You can add a popup to show you the caller id for quick debugging.
 

Wjbell

Member
Screenshot_20211120-141131.pngI cleared my system log and then ran a test and here's what's in my system log. Ignore the auto speakerphone and trees because I have an auto speakerphone macro that starts with any call. So this macro answers and then hangs up so the auto speaker phone went into effect but it doesn't have anything to do with it. So I called from another 916 phone and it should have went through but instead of got blocked. Now the + 1831 is an American area code. But it's not testing the validity of the area codes and where they're from is just seeing if that is in the number. And I didn't call from an 831 number anyway. The fact that the two area codes are in that rule makes it seem like it's checking both of the area codes to see if either one is in the calling number. The 916 is in the calling number but the 831 isn't So it's running the macro to block the call. I want the macro to look at each area code I have listed and if either one of them match the incoming call then it should bypass the action and let the call come through.
 

Wjbell

Member
View attachment 1626I cleared my system log and then ran a test and here's what's in my system log. Ignore the auto speakerphone and trees because I have an auto speakerphone macro that starts with any call. So this macro answers and then hangs up so the auto speaker phone went into effect but it doesn't have anything to do with it. So I called from another 916 phone and it should have went through but instead of got blocked. Now the + 1831 is an American area code. But it's not testing the validity of the area codes and where they're from is just seeing if that is in the number. And I didn't call from an 831 number anyway. The fact that the two area codes are in that rule makes it seem like it's checking both of the area codes to see if either one is in the calling number. The 916 is in the calling number but the 831 isn't So it's running the macro to block the call. I want the macro to look at each area code I have listed and if either one of them match the incoming call then it should bypass the action and let the call come through.
So I guess what I'm trying to say is bottom line if I make a rule to just block the 916 area code the macro works as expected. If I'm calling from a 916 area code the call will go through if I'm calling from any other area code the call will be blocked. When I try to add multiple area codes along with the 916 the macro fails and blocks every single call because I think it's looking for a combination of all those area codes.
 
Top