Pages Menu
TwitterRssFacebook

Posted by on May 19, 2015 in Learn Skype Web SDK

Learn Skype Web SDK Day 14 : Sending Instant Messages

Learn Skype Web SDK Day 14 : Sending Instant Messages

[contemplate-1]
View Demo

Once you’ve found the person you want to start a conversation with and set up and started the conversation – actually sending messages is a one-liner. However, the reason that it’s got it own section is that you can’t just send messages into a conversation once you’ve started it.

A newly created conversation will start Disconnected. When you call start() it will change to Created briefly before changing to Connecting. Once it’s been accepted by the other party it will change to Connected. Once one side closes the conversation its state will change back to Disconnected. You can only send IMs whilst the state is Connected, so you need to monitor this state.

To monitor the state, register a listener on the state property of the chatService, a member of the conversation. Do this before you call start() otherwise you’ll miss vital states:

[code language=”javascript”]
var application = new Skype.Web.Model.Application;
//do sign-in process
var conversation = application.conversationsManager.createConversation();
//set up the conversation, add participants etc.
conversation.chatService.state.changed(function(newState) {
//evaluate the new state
});
//…
conversation.chatService.start();
[/code]

Once the state has changed to Connected, you can then send messages, using this one-liner:

[code language=”javascript”]
conversation.chatService.sendMessage(‘message to send’);
[/code]

In the code sample below, once the user is signed in they can send instant messages to another user:

[code language=”javascript”]



[/code]

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.
[contemplate-2]

1 Comment

  1. On line 95 is an error, the SDK reacts poorly to not declared variables and breaks with an exception. The error is not easy to detect, as the errormessage tells something about an unexpected character.

Post a Reply

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