Sometimes you have to rely on others when you don’t poses the skills your self, well maybe this was more like hope someone comes to my rescue. This week I got a question about blocking caller ID. I knew what to use to solve it but didn’t know how to write the code. Luckily for me Keith from Got UC was able to help me out. Below is a MSPL script for blocking calls in Lync based on caller ID. Keith has also posted the code on gotUC as well. I have also created a link to my SkyDrive so people can download it rather than copy and pasting from the post which can screw the code up.
One thing you will notice about the script is that you will need to create a text file called BlockedTelephoneNumbers.txt. This file contains the blocked telephone numbers with two columns. One is the telephone number and the second is the action which in this case only requires the word “block”. Also static="false" is set which means when you make a change to the script it will reload it so no need to do any manual restarts of the application in Lync.
This is a pretty simple script that only blocks on the inbound caller id and does no other checks. Hopefully you only block the right numbers. You can also add some checks to this script. Only invites from the mediation server is one that comes to mind. This would block only calls from the PSTN and would avoid the script checking every single invite against the file which could get quite large.
So the potential to add some more checks and balances are possible but this script presents a great base to build a more complex call blocking process.
<r:applicationManifest r:appUri="http://www.gotuc.net/TelFilter" xmlns:r="http://schemas.microsoft.com/lcs/2006/05">
<r:requestFilter methodNames="ALL" strictRoute="true"/>
<r:file name="BlockedTelephoneNumbers" path="C:\Work\TelFilter\BlockedTelephoneNumbers.txt" delimitedBy="comma" keyColumnName="Phone" static="false">
<r:column name="Phone" />
<r:column name="Action" />
Module Name: TelFilter.am
// Main program.
Log ("Debugr", false, "We have a request - ", sipRequest.Method);
Log ("Debugr", false, "From - ", GetUserName(GetUri(sipRequest.From)));
Log ("Debugr", false, "To - ", GetUserName(GetUri(sipRequest.To)));
action = BlockedTelephoneNumbers[GetUserName(GetUri(sipRequest.From))].Action;
if(action == "block")
Log ("Debugr", false, "Exit. Rejected by policy");
Log ("Debugr", false, "Exit. Allowed by policy");
Click below to download code: