Microsoft Lync and Skype for Business have a rich set of .NET APIs which make it easy to extend the platform and integrate it with other applications. This blog helps explain how to use those APIs.

How to get the “is typing…” messages through UCMA

Posted: January 9th, 2012 | Author: | Filed under: UCMA 3.0 | Tags: , , , | 2 Comments »

If you’re writing a UCMA application that handles instant messaging, you may at some point want to replicate the effect that users of the Lync client get where a message shows up notifying you when the other person is typing. This makes it a bit easier for people to carry on a conversation over instant messaging without constantly interrupting one another. Triggering and receiving this notification is actually quite easy in UCMA, but the way to do it is not immediately obvious.

I’ll start with how to receive typing notifications: that is, how your UCMA application can find out when someone on the other end of an IM conversation is typing. You can do this by hooking up an event handler to the RemoteComposingStateChanged event on an InstantMessagingFlow object, which you can find on the Flow property of InstantMessagingCall. The “composing state” is just a fancy term for whether the remote party is typing or not, and there are two possible composing states: composing, and idle. Here’s what the code looks like for subscribing to the event:

imCall.Flow.RemoteComposingStateChanged +=
    new EventHandler<ComposingStateChangedEventArgs>

In your event handler, you can then check what the new state is and respond accordingly, as shown in the following code:

void OnRemoteComposingStateChanged(object sender,
    ComposingStateChangedEventArgs e)
    if (e.ComposingState == ComposingState.Composing)

Easy enough, right? Now, what if you want to have your application send that typing notification to a remote party? To do this, you can use the LocalComposingState property on InstantMessagingFlow:

imCall.Flow.LocalComposingState = ComposingState.Composing;

Once you’ve set the LocalComposingState property to ComposingState.Composing, UCMA will send typing notifications to the remote party every few seconds, so that the typing message continues to show up, until one of three things happens:

  • You send an IM using InstantMessagingFlow.BeginSendInstantMessage
  • You explicitly set LocalComposingState to ComposingState.Idle
  • The composing state timeout elapses

You can set the composing state timeout using the ComposingStateTimeout property on InstantMessagingFlow. After this number of seconds go by, the composing state will automatically revert back to Idle, unless you’ve set the ComposingState property again during that time.

// Typing notifications will stop being sent
// after 30 seconds.
imFlow.ComposingTimeoutValue = 30;

That’s more or less all there is to it. If you have any questions about how this works, don’t hesitate to write a comment or email me.

2 Comments on “How to get the “is typing…” messages through UCMA”

  1. 1 shabana Shaikh said at 9:00 am on March 27th, 2014:

    When i am posting message to chat room and enable filtering of that message i am getting “This message has been blocked and not posted to the room” So from where this message is coming/ how to remove that message/warning.

  2. 2 Guy said at 11:15 am on September 30th, 2014:

    Hi Michael,

    I am trying to implement this and have run into a couple of hiccups:

    1. Every ComposingState change causes the OnRemoteComposingStateChanged function to be called several times in the span of a couple seconds, with interchanging values for e.ComposingState – this means that, if I begin typing, the event is called and I do showTypingIcon(); but about 2 seconds later the function is called again with e.ComposingState = ComposingState.Idle! This causes the TypingIcon to only really be shown for about 2 seconds and then disappear! I tried setting ComposingTimeoutValue to 30 but it had no effect.

    2. Setting the LocalComposingState works great when I set it to ComposingState.Composing but has some weird 11 second(!) delay when I set it to Idle…

    Any ideas?

Leave a Reply

  • Note: Comment moderation is in use because of excessive spam. Your comment may not appear immediately.