2

Background - I am working on a Lync application which acts as a middle-man in conversations going to specific users. Basically, a call coming in to UserA is forwarded to UserB, but the caller isn't given UserB's details. From her point of view, she converses directly with UserA. Basically, the application manages two calls for each incoming call to UserA:

  1. from the caller to UserA
  2. from UserA (via impersonation as the caller) to UserB

Each message is received and is forwarded as is to UserB.

Problem There are a few scenarios in which I wish to give an automatic reply from the system. No problem so far, but I want to set a style for these "system" messages. When chatting in a normal Lync conversation, you are able to select font, color and size, as well as change the direction of the text.

Now, for regular communique between the two parties, I simply pass the messages on untouched - i.e., UserA receives a message from the caller, and the system sends the e.TextBody to UserB as is (e is InstantMessageReceivedEventArgs). I simply call:

instantMessagingFlow.BeginSendInstantMessage(Encoding.UTF8.GetBytes(e.TextBody),
    res =>
    {
        try
        {
            instantMessagingFlow.EndSendInstantMessage(res);
        }
        catch(Exception ex)
        {
            //handle exception
        }
    });

Now, in this case the formatting get completely lost. I have found no evidence of any sort of style data passed in the InstantMessageReceivedEventArgs...

I know it's possible to style the IM's using HTML so that sending the message becomes something like:

instantMessagingFlow.BeginSendInstantMessage(new ContentType("text/html"),
    Encoding.UTF8.GetBytes("<div style='color: blue;'>" + e.TextBody + "</div>"),
    res => 
    [...]

This gives me the text in the selected color, but I am having trouble selecting a font, or setting text alignment. No matter what I do, some of the font is displayed in Times New Roman (or is it Segoe UI? Whatever the default is...). I set font using font-family: Arial;. In some cases, it is simply ignored, but even when it works, setting direction: rtl; (most of the text is supposed to be right-to-left), or text-align: right; has no effect whatsoever...

Am I putting incorrect commands? Is there a specific command that I need to use for the text-alignment which isn't text-align?

Guy Passy
  • 694
  • 1
  • 9
  • 32

1 Answers1

0

If you are trying to send your messages on OCS Web or Window client then you need to format it in different way using X-MMS-IM-Format. For Lync 2010 Client you can use code snippet below:

string fontColor = "color: " + String.Format("{0:X2}{1:X2}{2:X2}", agentFontColor.R, agentFontColor.G, agentFontColor.B) + "; ";
            htmlMessage = "<html><body ><div style=\" font-family: " + agentFontName + "; " + agentFontBold + agentFontSize + fontColor + agentFontItalic + agentFontUnderline + " \">" + imText + "</div></body></html>";

agentFontBold should be : font-weight: bold; or font-weight: Normal; -as per requirement. agentFontSize should be : font-size: 11px - as per requirement. agentFontItalic should be : font-style: italic; or font-style: Normal; -as per requirement. agentFontUnderline should be : text-decoration: underline; or "" -as per requirement.

  • basically, the two differences that I can see between what I posted and your answer are - to have the color be in hex (which, having it be `blue` gives me the color I want... so no real need), and to put the messages in `` tags? You don't specifically mention `font-family` or text directionality / alignment. – Guy Passy Mar 22 '15 at 10:11