JSPM

  • Created
  • Published
  • Downloads 1853
  • Score
    100M100P100Q108258F
  • License MIT

Liveperson Agent Messaging SDK for NodeJS

Package Exports

  • node-agent-sdk

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-agent-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-agent-sdk

npm version npm downloads license

LivePerson Agent Messaging SDK for NodeJS
The SDK provides a simple wrapper for node js for the LivePerson messaging API.

Getting Started

  • Install: npm i node-agent-sdk --save
  • Run the example: Provide the following env variables and run npm run:
    • ACCOUNT - Your LivePerson account Id
    • USERNAME - Your LivePerson agent username
    • PASSWORD - Your LivePerson agent password
  • Run tests: npm test

Example

const Agent = require('node-agent-sdk');

const agent = new Agent({
    accountId: process.env.ACCOUNT,
    username: process.env.USERNAME,
    password: process.env.PASSWORD
});

agent.on('connected', () => {
    console.log(`connected... ${agent.agentId}`);

    agent.subscribeExConversations({
        'convState': ['OPEN']
    }, (err, resp) => {
        console.log('subscribed successfully', err, resp);
    });
});

API Overview

###Agent class

new Agent({
    accountId: String,
    username: String,
    password: String,
    token: String, //a bearer token instead of username and password
    csdsDomain: String, //override the CSDS domain if needed
    requestTimeout: Number, //default to 10000 milliseconds
    errorCheckInterval: Number, //defaults to 1000 milliseconds
    apiVersion: Number //Messaging API version - defaults to 2
});

###Events

agent.on('connected', (msg) => {
    //once socket connected to the server
});

agent.on('notification', (message) => {
    //listen on all notifications
});

agent.on('.MessagingEvent', (body) => { //specific notification type
    //listen on all notifications
});

agent.on('.ams.ms.QueryMessages', (body, requestId) => { //specific response type
    //listen on all notifications
});

agent.on('closed', (reason) => {
    //socket closed
});

agent.on('error', (err) => {
    //Some error happened
});

API

All requests types are dynamically assigned to the object on creation. The supported API calls are a mirror of the API, please read the documentation carefully for full examples: The list of api calls are:
getClock, getBrands, getBrandProfile, setBrandProfile, agentRequestConversation, consumerRequestConversation, subscribeExConversations, unsubscribeExConversations, updateExConversationSubscription, updateConversationField, publishEvent, queryMessages, updateRingState, subscribeRoutingTasks, updateRoutingTaskSubscription, setUserProfile, getUserProfile, setAgentState, subscribeAgentsState

registerRequests(arr)

You can dynamically add functionality to the sdk by registring more requests. For example:

registerRequests(['.ams.AnotherTypeOfRequest']);
//Will register the following api
agent.anotherTypeOfRequest({/*some data*/}, (err, response) => {
    //do something
});

request(type, body[, headers], callback)

You can additionally call any request api functionality as follows:

agent.request('.ams.aam.SubscribeExConversations', {
        'convState': ['OPEN']
    }, (err, resp) => {
        console.log('subscribed successfully', err, resp);
    });

Further documentation