Sending formatted text with UCMA 2.0

霸气de小男生 提交于 2019-12-21 05:06:40

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/885505/sending-formatted-text-with-ucma-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!