Skip to content

Instantly share code, notes, and snippets.

@adoprog
Last active August 9, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adoprog/155f55467be5624266068375514d19d1 to your computer and use it in GitHub Desktop.
Save adoprog/155f55467be5624266068375514d19d1 to your computer and use it in GitHub Desktop.
Lync - subscribe to IM
private static LyncClient client;
// Your custom class that handles conversation events
private static LyncConversationManager conversation;
static void Main(string[] args)
{
client = LyncClient.GetClient();
conversation = new LyncConversationManager(brain, client);
conversation.StartListening();
Console.ReadKey();
}
...
public void StartListening()
{
lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
}
private void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
{
e.Conversation.ParticipantAdded += Conversation_ParticipantAdded;
foreach (var key in e.Conversation.Modalities.Keys)
{
Modality val = e.Conversation.Modalities[key];
if (val != null)
{
val.Accept();
}
}
}
...
private void Conversation_ParticipantAdded(object sender, ParticipantCollectionChangedEventArgs e)
{
if (e.Participant.IsSelf == false)
{
var imModality = (InstantMessageModality) e.Participant.Modalities[ModalityTypes.InstantMessage];
imModality.InstantMessageReceived += ImModality_InstantMessageReceived;
}
}
private void ImModality_InstantMessageReceived(object sender, MessageSentEventArgs e)
{
InstantMessageModality im = (InstantMessageModality)sender;
if (!im.Participant.IsSelf)
{
// Here goes the code that will forward and respond to the messages
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment