Sending formatted text with UCMA 2.0

2019-03-30 09:57发布

Has anyone been successful in sending formatted text over an Instant Message flow using the UCMA 2.0 sdk?

It doesn't seem to be very well documented on MSDN. Are there any examples out there? Any books that talk about this?

2条回答
在下西门庆
2楼-- · 2019-03-30 10:54

Ran into this issue myself earlier today on a project at work. I don't have my code accessible to me at the moment, but it's essentially capable by doing the following...

MimePartContentDescription text;
MimePartContentDescription html;
MimePartContentDescription package;

text = new MimePartContentDescription(
    new ContentType("text/plain"),
    Encoding.UTF8.GetBytes(message_text) );

html = new MimePartContentDescription(
    new ContentType("text/html"), 
    Encoding.UTF8.GetBytes(message_html) );

package = new MimePartContentDescription(
    new ContentType("multipart/alternative"), null
);

package.Add(html);
package.Add(text);

// Call BeginSendMessage ... SendMessageCompleted is async callback.
imFlow.BeginSendMessage(package.ContentType, package.GetBody, SendMessageCompleted, imFlow)

This method wraps two versions of the message into a single 'package' (if you will) that will degrade gracefully, providing the plain text version to clients that cannot handle the HTML, or will provide the HTML if the client supports it.

Credit goes to 'mdip' for posting the above code solution...

http://social.msdn.microsoft.com/Forums/en/ucmanagedsdk/thread/c532bbb9-f593-4443-85af-4e0708b8532c

查看更多
贼婆χ
3楼-- · 2019-03-30 10:59

My understanding is that message prompts are simply strings. If you want to add formatting to a string, a suggestion could be to use common html formatting in the prompt then pump the prompt received into an HTML aware control.

查看更多
登录 后发表回答