Converting a Node Agent SDK project to Messaging Platform SDK

Node Agent SDK will continue to work after Messaging Platform SDK has launched, and we will continue to support it for some time for existing applications, but, we will highly encourage conversion to the new sdk. We are planning on documenting two methods of conversion:

Partial conversion - node-agent-sdk applications must consume raw json results returned from UMS and construct json requests. This is still possible with the new sdk, though not recommended, but it does make for an easy conversion and the application would get several benefits of the new SDK, such as the reconnection logic. The code must still be converted over to use async/await and a few other minor changes, we estimate this should take approximately 1-2 days of developer time.

Full conversion - This will be our recommendation for new projects, in this conversion, the application would use all of the new objects and methods created as an interface for the UMS websocket api. For simple applications this can be done quickly, but for larger projects, this may involve removing large chunks code whose job is now done inside the SDK, we estimate this should take approximately 1-2 weeks of developer time. In order to use REST API through the SDK, applications will need this type of conversion.

For example in node-agent-sdk, to send a message, the code looks like this:

connection.publishEvent({
    dialogId: 'MY_DIALOG_ID',
    event: {
        type: 'ContentEvent',
        contentType: 'text/plain',
        message: 'hello world!'
    }
}, callbackFunc);

For partial conversion you can still send the json, but it must be sent as "body" and the request type must now be specified in the request instead of being implied by the function name. Also, the function should now be awaited:

await connection.send({
    type: '.ams.ms.PublishEvent',
    body: {
        dialogId: 'MY_DIALOG_ID',
        event: {
            type: 'ContentEvent',
            contentType: 'text/plain',
            message: 'hello world!'
        }
    }
});

For full conversion, the code would simply be:

await conversation.sendMessage('hello world');

All Request Types

In the previous section, we described how to convert the publishEvent request to MPSDK. ALl that was required was to wrap the existing partial json request, turning it into a full json request. Then execute the request by invoking connection.send:


const partialJsonRequest = {
    dialogId: 'MY_DIALOG_ID',
    event: {
        type: 'ContentEvent',
        contentType: 'text/plain',
        message: 'hello world!'
    }
};

const requestType = '.ams.ms.PublishEvent';

const fullJsonRequest = {
    type: requestType,
    body: existingJsonRequest
}

const response = await connection.send(fullJsonRequest);

The other node-agent-sdk requests can be converted in the same way by using the following request type:

const REQUEST_TYPES = {
    getClock:                      '.GetClock',
    agentRequestConversation:      '.ams.cm.AgentRequestConversation',
    subscribeExConversations:      '.ams.aam.SubscribeExConversations',
    unsubscribeExConversations:    '.ams.aam.UnsubscribeExConversations',
    updateConversationField:       '.ams.cm.UpdateConversationField',
    publishEvent:                  '.ams.ms.PublishEvent',
    updateRingState:               '.ams.routing.UpdateRingState',
    subscribeRoutingTasks:         '.ams.routing.SubscribeRoutingTasks',
    updateRoutingTaskSubscription: '.ams.routing.UpdateRoutingTaskSubscription',
    getUserProfile:                '.ams.userprofile.GetUserProfile',
    setAgentState:                 '.ams.routing.SetAgentState',
    subscribeAgentsState:          '.ams.routing.SubscribeAgentsState',
    subscribeMessagingEvents:      'ms.SubscribeMessagingEvents',
    generateURLForDownloadFile:    '.ams.ms.GenerateURLForDownloadFile',
    generateURLForUploadFile:      '.ams.ms.GenerateURLForUploadFile',
    generateDownloadToken:         '.ams.ms.token.GenerateDownloadToken'
};

To convert an existing node-agent-sdk request to a full request, look up the type in the table. If the request was made in node-agent-sdk as connection.publishEvent(existingJsonRequest); you would convert like this:

const fullJsonRequest = {
    type: REQUEST_TYPES['publishEvent'],
    body: existingJsonRequest
}

const result = await connection.send(fullJsonRequest);