Zax
Zax

Reputation: 3010

UCWA: Unable to send/Receive formatted text

I have a simple chat application working fine with plain text implemented using UCWA api in a ASP.Net MVC web application. I have to implement a formatted text next.

Referring to UCWA: integrating advanced chat options , I go to know that, before sending the message to using ucwa.Transport.clientRequest we have to set the contentType to text/html which currently is text/plain.

So i have the function to send a message as shown below:

function sendMessage(displayName, msg, timestamp) {

            var encodedMsg = encodeURIComponent(msg);

            ucwa.Transport.clientRequest({
                url: messagingLinks.SendMessage + "?SessionContext=" + ucwa.GeneralHelper.generateUUID(),
                type: "post",
                contentType: "text/html",
                data: encodedMsg,
                callback: function () {
                    addMessageToChat(displayName, encodedMsg, timestamp);
                }
            });
        }

The implementation of handleMessage() is as shown below:

function handleMessage(data, parts) {

            alert("Inside Handle message");

            if (!data._embedded.message._links.plainMessage) return false;
            
            var message = decodeMessage(data._embedded.message._links.plainMessage.href);

            var decodedMsg = decodeURIComponent(message);
            addMessageToChat(data._embedded.message._links.participant.title, decodedMsg, formatTime(new Date(Date.now())));
        
        }

The problem in the above implementation is that, on the receiving end, the handleMessage() method is not entered which means i'm not receiving the incoming message.

Can anyone point me where i'm going wrong and Are the any other changes i need to do along with the above changes, so that i can send a formatted text across. A sample will be really helpful regarding the same.

Any suggestion would also be good enough. Thanks in advance.

Edit:

As suggested i have modified my makeMeAvailable method. below is the definition of the same in Authentication.js:

function makeMeAvailable() {
                if (!_authenticated) {
                    cache.read({
                        id: "main"
                    }).done(function (cacheData) {
                        if (cacheData) {
                            var data = {
                                SupportedModalities: ["Messaging"],
                                supportedMessageFormats: ["Plain","Html"]
                            };

                            transport.clientRequest({
                                url: cacheData._embedded.me._links.makeMeAvailable.href,
                                type: "post",
                                data: data,
                                callback: handleState
                            });
                        }
                    });
                } else {
                    handleState({
                        status: 204
                    });
                }
            }

However, the output is still the same. The second suggestion regarding the communication API, i'm unable to locate it.

Any suggestions with this?

Upvotes: 0

Views: 578

Answers (2)

Monica Thiery
Monica Thiery

Reputation: 11

Here are two reasons I did not receive messages sent through UCWA API:

  • Charset: Default value was ISO-8859-1, I had to use UTF-8 to receive any message.
  • Negotiated message formats: The receiving contact only supported plain message format, but the messages were sent with text/html content type.

Upvotes: 1

ShelbyZ
ShelbyZ

Reputation: 1504

When it comes to the messaging formats in UCWA it should be known that by default all endpoints that support the messaging modality by default support plain messages. It is interesting to note that this limitation does not prevent sending of HTML formatted messages as you have seen in your examples.

There are two ways to enable HTML formatted messages as follows:

  1. When issuing a request to makeMeAvailable supply an SupportedMessageFormats (array) and include Html
  2. Issue a PUT request to communication and include Html in SupportedMessageFormats

Until either 1 or 2 has executed successfully it will be impossible to receive HTML formatted messages.

Upvotes: 0

Related Questions