Accessing Groove Messages

Applies to: SharePoint Workspace 2010 | Visual Studio 2008

You can perform a variety of operations on instant messages. You can create and send messages, replies, and forwards, and you can read message contents or metadata associated with messages, such as contact information or message status.

If your application is sending messages from a managed identity, your application may not be able to send messages to contacts whose identities have not been verified. If a management policy forbids the managed identity to send a message to an unverified contact, a GrooveMessagesCreate, CreateForward, or CreateReply operation will fail if any of the recipients are not verified, and the message will not be sent to any of the recipients.

Reading Messages and Sending Responses

This example shows you how to read through messages and reply to each with a response.

See Accessing Accounts and Identities for an example of how to get account information, which includes the HTTP Post URL for the GrooveMessages service.

// Set up a GrooveMessages service
GrooveMessages.GrooveMessages msgsSvc= new
  GrooveMessages.GrooveMessages();
msgsSvc.GrooveRequestHeaderValue = new
  GrooveMessages.GrooveRequestHeader();

// Get the Groove request key and host and port information
// from the registry. See Reading Groove Registry Keys
string requestKey = ...;
string HTTPAddressAndPort = ...;

// Get the Groove IdentityURL from your account information
// See example in Accessing Accounts and Identities
string identityURL = ...;

msgsSvc.GrooveRequestHeaderValue.GrooveIdentityURL = identityURL;
msgsSvc.GrooveRequestHeaderValue.GrooveRequestKey = requestKey;

// The GrooveAccounts.Account2 returned by GrooveAccounts.Read
// provides the HTTP Post URL for the Groove Messages service.
GrooveAccounts.Account2 act2 = ... 
msgsSvc.Url = HTTPAddressAndPort + act2.Messages;

// Read the messages from the service
GrooveMessages.Message[] msgs =
  msgsSvc.Read(true,true,true,true,true,true,
  GrooveMessages.MessageCategory.New,true);

// Create a response message for each incoming message
foreach (GrooveMessages.Message msg in msgs)
{
  GrooveMessages.MessageHeader msgHead= new
    GrooveMessages.MessageHeader();
  GrooveMessages.MessageContent msgCont = new
    GrooveMessages.MessageContent();
  GrooveMessages.MessageContact msgRecip = new
    GrooveMessages.MessageContact();

  // Put the response message together
  msgRecip.URI = msg.MessageHeader.Sender.URI;
  msgRecip.Name = msg.MessageHeader.Sender.Name;

  GrooveMessages.MessageContact[] recipients = new
    GrooveMessages.MessageContact[] { msgRecip }; 
  msgHead.Recipients = recipients;
  msgHead.HasAttachments = false;
  msgHead.HasVoiceMemo = false;
  msgCont.Body = "We have received your message.";

  // Send the response
  msgsSvc.Create(msgHead, msgCont);
}

See Also

Reference

GrooveMessages Web Service