Pages Menu
TwitterRssFacebook

Posted by on May 18, 2015 in Everything Else, Learn Skype Web SDK

Learn Skype Web SDK Day 13 : Starting a New IM Conversation

Learn Skype Web SDK Day 13 : Starting a New IM Conversation

[contemplate-1]
View Demo

We can use Skype for Web API to start a new IM conversation with someone. In order to do this, we need at least one person object representing the person we want to start a conversation with. If you want to start a group conversation with more than one person then you will need to have multiple person objects to repesent these people. Once we have this we are ready to create the conversation.

Conversations are started, stopped and managed from the conversationManager, which is a member of the top-level parent Application. Creating a new conversation with Skype for Web API is actually a lot easier than you might think. It consists of 4 distinct steps: create the conversation, add participants, register the new conversation, start the conversation.

Step 1 – Create the conversation. Like the rest of Skype for Web API – new objects are not ever instantiated in isolation – they always come from a parent. In this case we use the parent conversationManager to create a new conversation:

[code language=”javascript”]
var application;
//do sign-in process to instantiate application object
var conversation = application.conversationsManager.createConversation();
[/code]

Step 2 – Add the participants. You don’t need to add yourself, but you need to add anyone else in the conversation. Assuming you already have the person object:

[code language=”javascript”]
var conversationParticipant = conversation.createParticipant(person);
conversation.participants.add(conversationParticipant);
[/code]

Step 3 – Register the conversation. Before you start the conversation you need to tell the conversationsManager about it by adding it into its list of conversation:

[code language=”javascript”]
application.conversationsManager.conversations.add(conversation);
[/code]

Step 4 – Start the conversation! You’re now ready to begin the conversation. Unlike the Skype for Business client you don’t actually need to send an initial message when begining a new conversation:

[code language=”javascript”]
conversation.chatService.start();
[/code]

You won’t see anything happening, but the participant should receive an incoming IM popup. Assuming they accept the popup, the conversation has now started.

[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. Hi!

    It is possible to establish a conversation with a federated user?

Post a Reply

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