Learn Skype Web SDK Day 4 : Getting Your Own Information
This is one post in a series of more than 30, devoted to helping you get up to speed quickly with the new Skype Web SDK. Each lesson comes with source code (in GitHub) and a working demo page so you can see what it does. Check out the full list of posts on the Skype Web SDK page.
View Demo
We’ve already covered how to get and subscribe to presence information, but Skype for Business (Lync) contains a lot more information about the logged-in user, which we can get at and display.
You’ve already met the mePerson object when getting presence, but there’s other information there as well. In this code example, I load the Display name, Job Title and Department information and display them. These attributes are available to you once you’ve logged in.
Whilst most of the properties are basic types, like strings and can just be read normally, the Note property is a complex type. It has two properties: text and note. This is because it’s used to show both Personal Note (sometimes called the Message of the Day, the thing at the top of the Lync client that lets you tell people what you’re up to), but also Out of Office messages.
For Out of Office messages, the type property will be “OutOfOffice” and for personal notes it will be “Personal”. The text property will be the actual text of the Out of Office / Note.
<div class="form-horizontal"> <div class="form-group"> <label for="username" class="col-sm-2 control-label">Username</label> <div class="col-sm-10"> <input type="email" class="form-control" id="username" placeholder="Email"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">Password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="password" placeholder="Password"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button class="btn btn-default" id="btnLogIn">Log in</button> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button class="btn btn-default" id="btnLogOut">Log out</button> </div> </div> </div> <div> <span id="loginStatus"></span> </div> <hr/> <div> Display Name: <span id="lblDisplayName"></span><br/> Department: <span id="lblDepartment"></span><br/> Job Title: <span id="lblTitle"></span><br/> Email: <span id="lblEmail"></span><br/> Location: <span id="lblLocation"></span></br> Personal Note: <span id="lblNote"></span><br/> </div> <script type="text/javascript"> $(function () { var client; $(function () { 'use strict'; Skype.initialize({ apiKey: 'SWX-BUILD-SDK', }, function (api) { client = new api.application(); // whenever client.state changes, display its value client.signInManager.state.changed(function (state) { $('#loginStatus').text("Login State: " + state); }); }, function (err) { alert('Error loading Skype Web SDK: ' + err); }); <span style="line-height: 1.5;">$('#btnLogIn').click(function () {</span> // start signing in client.signInManager.signIn({ username: $('#username').val(), password: $('#password').val() }).then(function () { //log in worked! alert('Logged in!'); GetOwnInfo(); }, function (error) { //Something went wrong. alert(error); }); }); $('#btnLogOut').click(function () { // start signing out client.signInManager.signOut() .then(function () { //log out worked! alert('Logged out!'); }, function (error) { //Something went wrong. alert(error); }); }); function GetOwnInfo() { var me = client.personsAndGroupsManager.mePerson; me.displayName.get().then(function (value) { $('#lblDisplayName').text(value); }); me.department.get().then(function (value) { $('#lblDepartment').text(value); }); me.title.get().then(function (value) { $('#lblTitle').text(value); }); me.email.get().then(function (value) { $('#lblEmail').text(value); }); me.location.get().then(function (value) { $('#lblLocation').text(value); }); me.note.text.get().then(function (value) { $('#lblNote').text(value); }); } }); </script>
Demo Online
You can try this code out against your own Skype for Business environment by going to the demo page. From here you can also download the code from GitHub if you want to host it locally, or take it and use it in your next project.
Good to Know
- Before you can run this code, make sure you've read my post on all the prerequisites you need to have in place.
- You don't have to copy the code from here - it's all on GitHub!
- If you liked this post, there are more! Check out the dedicated Skype for Web SDK Collection page, or signup to the newsletter
- Need a Skype for Web SDK solution, but not in a position to build yourself? Hire me!