Pages Menu

Posted by on May 21, 2015 in Learn Skype Web SDK | 0 comments

Learn Skype Web SDK Day 16 : Doing More with History Service

Learn Skype Web SDK Day 16 : Doing More with History Service

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

If you’ve registered a listener on new activityItems being added then you probably won’t need anything else, but the historyService object also has a unreadActivityItemCount property and a markAllAsRead() method which you can use to poll for unread messages.

You can also use the historyService to provide rock-solid delivery notification and feedback for a great user experience when sending messages. When you send a message, it goes into the activityItems collection immediately (with the direction of Outgoing). There is a status property you can monitor for the outcome of delivery of that message. Initially the status will change to Pending. Once the message has been delivered it will change to Suceeded, if it can’t be sent it will change to Failed. There is also a changed() event you can listen on.

We can add this event when evaluating new items being added to the historyService object:

[code language=”javascript”]
conversation.historyService.activityItems.added(function (newMsg){
if (newMsg.type() == ‘TextMessage’)
var direction;
if (newMsg.direction() == ‘Incoming’)
direction = “<--"; else { direction = "-->“;
newMsg.status.changed(function (newStatus) {
//do something with newStatus

In this code snippet we’re first checking that the new entry in the historyService is a TextMessage. After that we evaluate the direction the message is moving in and populate a variable with an arror signifying the direction. In a real project you would use this variable to make a decision about how to display the message, such as a different coloured bubble, or different alignment etc.

For outgoing messages (in the example, messages which are not Incoming we also register for the changed event of the status of the message. We can use this to provide feedback to the user about what’s happening with their message.

[code language=”javascript”]

Conversation State:

    Send Message Status:


    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.

    Disclaimer: This is sample code, intended to inform and educate. It is not production-ready and is lacking key components such as error handling. You use it entirely at your own risk. You should fully understand the effects, limitations and risks of the code before executing, and understand the implications of any set-up steps. By using these code examples you are using the Skype Web SDK, so you should read the Skype Software License Terms to which you are agreeing.

    Good to Know

    Post a Reply

    Your email address will not be published. Required fields are marked *

    This site uses cookies to help make this website better. By continuing to use this site we’ll assume you’re OK with that (implied consent).