The Group Chat SDK supports both interactive and management scenarios. Use the following procedures to interact with a chat room and participate in the conversation.

Task

Procedure

Connect to Group Chat

  1. Connect to Office Communications Server using UCMA 2.0 Core SDK, and establish a local endpoint.

  2. Construct a GroupChatEndpoint .

  3. Invoke BeginEstablish(AsyncCallback, Object) .

Browse chat rooms

  1. Connect to Group Chat.

  2. Obtain a reference to GroupChatServices .

  3. Invoke one of the browse methods on GroupChatServices :

These methods return a collection of ChatRoomSnapshot objects. A snapshot is a summary of the chat room which includes a currently active user count.

Query chat history for multiple chat rooms

  1. Connect to Group Chat.

  2. Browse chat rooms and identify the Chat room URI of the chat rooms you wish to query.

  3. Construct a query using the ChatHistoryQueryOptions class.

  4. Obtain a reference to GroupChatServices .

  5. Invoke BeginQueryChatHistory(ChatHistoryQueryOptions, AsyncCallback, Object) .

Join a chat room

  1. Connect to Group Chat.

  2. Construct an instance of ChatRoomSession .

  3. Identify the name or URI of a chat room you wish to join.

  4. Subscribe to events, such as:

  5. Invoke BeginJoin(Uri, AsyncCallback, Object) .

Send and receive chat messages

  1. Join a chat room.

  2. Receive inbound messages and changes to chat room properties as appropriate, based on the events to which you are subscribed.

  3. Upon receiving a ChatMessage :

    • View the raw content by accessing the MessageContent property.

    • Parse the formatted content by accessing the FormattedMessageParts collection. A message can consist of alert notifiers, story titles, plain text, hyperlinks, chat room links, emoticons, and downloadable file links.

    • View other metadata about the message by accessing the MessageAuthor and Timestamp properties.

  4. Post a message to the chat room using BeginSendChatMessage(FormattedOutboundChatMessage, AsyncCallback, Object) .

Post a chat room link, hyperlink, emoticon, alert, or story message

  1. Join a chat room.

  2. Construct a FormattedOutboundChatMessage , supplying a story title and alert indicator as desired.

  3. Append formatted message parts using:

  4. Post the message to the chat room using BeginSendChatMessage(FormattedOutboundChatMessage, AsyncCallback, Object) .

Upload files

  1. Join a chat room.

  2. Construct an instance of ChatRoomFileUploadJob .

  3. Subscribe to ProgressChanged on the job instance to monitor progress of the upload.

  4. Invoke BeginUploadFile(ChatRoomFileUploadJob, AsyncCallback, Object) on the chat room session to begin uploading the file.

  5. If desired, cancel the file transfer operation by invoking CancelJob () () () () on the job instance.

Download files

  1. Join a chat room.

  2. Receive a message which contains a link to a file that you wish to download.

  3. Find the MessagePartFileDownloadLink among the FormattedMessageParts of the chat message.

  4. Construct an instance of ChatRoomFileDownloadJob .

  5. Subscribe to ProgressChanged event on the job instance to monitor progress of the download.

  6. Invoke BeginDownloadFile(ChatRoomFileDownloadJob, AsyncCallback, Object) on the chat room session to begin downloading the file.

  7. If desired, cancel the file transfer operation by invoking CancelJob () () () () on the job instance.

View recent chat history of a chat room

  1. Join a chat room.

  2. Invoke BeginGetRecentChatHistory(Int32, AsyncCallback, Object) .

Store and retrieve a bundle of user preferences for your application

Note Note

This special case scenario is useful for applications that store distributed, application-specific user settings similar to those stored by the Group Chat client. It can also be used to retrieve preferences used by the Group Chat client, but the data encoded in the results is not a published format.

  1. Connect to Group Chat.

  2. Serialize your application's preferences to a string, choose an identifying label, and construct an instance of GroupChatPreferenceBundle .

  3. Obtain a reference to GroupChatServices .

  4. Invoke BeginSetPreferenceBundle(GroupChatPreferenceBundle, AsyncCallback, Object) .

  5. If desired, save the preference bundle locally, and record the sequence ID returned from EndSetPreferenceBundle(IAsyncResult) .

  6. Invoke BeginGetPreferenceBundle(String, Int32, Boolean, AsyncCallback, Object) to retrieve the preference from the server at a later date. Supply the last known sequenceID when invoking this method. If the last known sequenceID is less than the current sequenceID stored on the server, the server will respond with new preference data. If the sequenceID matches, the server will return an empty result.

Important note Important

In all of the Group Chat scenarios, you are instructed to invoke the appropriate BeginXXX(...)method to perform the desired action. The arguments to this method include the callback delegate which will be invoked when the asynchronous operation is completed. Then, according to the standard IAsyncResultpattern, you invoke the matching EndXXX(...)method to retrieve the result of the operation. Group Chat API users should be familiar with the asynchronous programming pattern. For more information, see Asynchronous Programming Overview.