Call Forwarding with MSPL Scripts

A while ago, I had to research ways to implement a server-side call forwarding process for a Lync Server 2013 environment. While hunting, I found that there is a script language provided by Microsoft that can help with these types of scenarios. MSPL stands for Microsoft SIP Processing Language and can let you intercept incoming SIP requests (calls, IM messages, etc) and do what you need to do with them.

This is very useful (and powerful) since it lets you create workflows and routing that might not exist within the existing Lync management tools.

At first, the process felt like jumping through too many hoops and hurdles for a pretty simple redirection, but once I got familiar with putting the pieces in place and using it for a bit, it is pretty simple actually.

This post will serve as a reminder for myself, and anyone else that might find it useful, in the event I have to setup the same thing again in the future.

The steps involved to get this up and running are…

  1. Create a new network shared folder, where you will store your MSPL script files. Somewhere that the Lync servers will be able to access.
  2. Create a new empty text file in that share, and rename it to be something like CallForwarding.am.
  3. Fill this in with your script contents, which you can use the example from Microsoft to get started (https://msdn.microsoft.com/en-us/library/office/dn439073.aspx)
  4. In the Microsoft example, look for the toUri = … line and the IF loop below it. Replace that section with something like…
    toUri = GetUri(sipRequest.To);
    toUserAtHost = Concatenate(GetUserName(toUri), “@”, GetHostName(toUri));
    telNum = GetUserName(toUri);
    if ((ContainsString(toUserAtHost, “+12125551212@YourDomain.com”, true)) ){   Respond(“302″,”Moved Temporarily”,”Contact=<sip:ForwardCallsToThisPerson@YourDomain.com>”);    return;}
    *That last line, the If statement one, you can copy/paste that for as many different # forward scenarios you want to handle. Each phone # you forward gets its own If statement line.
  5. Or instead of doing step 4, you can download the CallForwarding.am file I put up on GitHub, which is at: https://github.com/gregbesso/LyncCallForwarding
  6. Create a new server application on your Lync pool, by running something like the following from the Lync Management Shell…
    New-CsServerApplication –Identity “registrar:YourPool.YourDomain.com/CallForwarding” –Uri http://YourDomain.com/CallForwarding -ScriptName “\\Server\Share\LyncFiles\CallForwarding\CallForwarding.am” –Critical $False –Enabled $False
  7. Enable this new server application from the Lync admin console in the browser. Click Topology > Server Application, then highlight this new item you created and click Actions > Enable.

This has come in handy, and there were several online resources that helped me get up to speed with this MSPL scripting concept. Here are a handful of the sites that helped me get this up and running…

Microsoft, “How to forward IM invite to a different target”
https://msdn.microsoft.com/en-us/library/office/dn439073.aspx
Microsoft, “MSPL Script Sample…”
https://msdn.microsoft.com/en-us/library/office/dn439065.aspx
Ken’s Unified Communications Blog, “Rerouting Incoming Lync Calls…”
http://ucken.blogspot.com/2012/02/re-routing-incoming-calls-to.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s