Learning to dive: UCMA Coding
Introduction
As you know, there’s another section of this blog devoted to scuba diving. Learning to scuba dive takes a bit of time, and requires some effort from the student. Firstly, there’s paperwork, quite a lot of paperwork. Then there’s dive theory: not too much, but just enough to ensure the basics are understood. There’s a handbook full of useful information and a DVD. A series of mini-tests confirms your understanding and a final exam ensures it. Then there’s pool sessions. There’s a lot to take in: the kit, putting it all together, getting in, swimming around, performing particular skills. Finally, a series of dives outside in “the real world” brings everything together and you’re ready to go diving for real.
Luckily your instructor is on hand to help you through all these stages. Imagine how complicated things might be if you didn’t have someone with you who’d done it all before, who could explain why things are the way they are, and provide tips and tricks. Even with an instructor, many people hit a wall partway through their training – “I can’t do this anymore”, “It’s not worth the stress”, “Maybe I’ll just take up rock climbing”.
Everyone agrees though, when the teaching is done, the course completed, the qualification obtained, the holiday booked and you jump into the gin-clear waters of Egypt: it’s all been worth it. Suddenly, everything comes together and you start reaping the benefit of all that hard work.
Coding in UCMA always seems to me a bit like learning to dive. There’s a lot of steps to be completed, quite a lot of work that needs to be put in. However what can be achieved is pretty cool and very powerful.
UCMA Coding
What it is
The Unified Communications Managed API (UCMA) is a Microsoft API available to Lync developers. As opposed to, say, the Lync Client SDK, this allows you to write programs which are usually wrapped into Windows services, which can interact directly with the Lync Server.
What it can do
A common use for UCMA is to write programs which run as autonomous agents on the Microsoft Lync architecture: bots. Bots can have their own identity and so can be added to contact lists just like users. Behind the bot you can write whatever you want. An example might be a weather bot which tells you the weather forecast each time you talk to it. More sophisticated examples include applications like TrainMe, which delivers video-based content based on training you’ve already received.
Using the UCMA framework you can keep track of conversations and instant message texts. UCMA application have some special powers in the Lync system, which means they can join conference sessions unseen and record everything that goes on, for instance. I haven’t tried it yet, but a UCMA implementation of the Turing test would be a fun project.
A UCMA-based bot can also open a Conversation Window Extension (CWE) when in a conversation with a user. A CWE is a pop-out webpage which the Lync client will display. Behind the scenes the bot can interact with the page, send it content and receive information about what’s happening on it. It’s like a sharing surface for both the user and bot. In this picture, TrainMe has opened a CWE in order to show training content:
What you need
In order to write UCMA code you need a Lync Application Server. This will only run within a Lync environment, which in turn will only run within an AD environment.
If you’re setting up a development environment, at a minimum you will need 3 servers: a domain controller, a Lync server and an Application server. In order to interact with your bot when it’s running you’ll also need client machines, running the Lync client application.
Unless you have an entire Lync infrastructure running on your development machine, or Visual Studio running on your Lync application server (both somewhat unlikely) you’ll also soon discover that a lot of the debugging tools you’re used to can’t be used: as nothing will work unless you run the code on a properly provisioned Lync application server.
Why it’s hard
UCMA development isn’t totally straightforward. For a start, there’s quite a lot of infrastructure requirements up front. Then, you need to provision a Lync Application Server, and ensure it is trusted within the Lync environment. Then you’ll need to create a Trusted Application Pool, configure replication from the central management store, define a trusted application, then one or more endpoints (using Power Shell). That’s before you start writing code!
I’ve glossed over these tasks, as well as some of the hardware requirements. The truth is, I don’t fully understand them! They aren’t my area of expertise, and this is one of the reasons UCMA development has a steep learning curve: by the time you get to actually writing code you’ve had to learn so much new stuff you probably don’t have any time left. I’m fortunate in that I have excellent colleagues who have been here before and help with the set up costs. If you want more information about Lync infrastructure, I’d recommend Tom and Justin‘s blogs, as well as CodeLync for more information on Lync development.
When you do get to write the code there’s a much-better-than-it-used-to-be-but-still-not-entirely-straightforward set of steps you need to go through in order to link your application to the endpoint you created so that you will receive notification of any new conversations and can generally do stuff. Due to the nature of the environments in which it is working, most of the API calls are asynchronous so you have to be diligent in your coding to avoid spaghetti code (especially when you consider that just start an instant messaging conversation with someone can involve more than 5 calls, which have to be chained together). I’m not trying to put you off: it’s actually great fun writing UCMA applications and the actual API is really good. I just want you to understand the set-up costs.
So, what now?
I’ve outlined some of the pain points with UCMA. I’ve hopefully also whetted your appetite for them. I think they are a valuable addition to any business setup involving Lync, as the interactions they allow with users are simple and effective.
If you’re interested in writing UCMA applications, I’d recommend this book: Professional Unified Communications Development with Microsoft Lync Server 2010 (Wrox Programmer to Programmer). It has good information about setting up application servers and configuring a test system as well as actual UCMA development. There’s also plenty of other material relating to Lync development using the other SDKs and APIs.
In my next blog post I’m going to be talking about how you can avoid all the pain of setting up, creating and maintaining UCMA applications and instead just enjoy the glory of your business processes being invigorated with Lync!
Hi. I need to develop lync bot using UCMA 4.0. Do I need to create user endpoint for the same or application end point is needed.Also, should I use separate computer for development and lync server 2013. Please let me know the same as I am new to this.