Note: These are merely samples intended to demonstrate API concepts and potential use cases. This code is not officially supported by LivePerson.

Running The Sample Apps

The best way to use the SDK is to extend the Agent class with your own logic and then instantiate this object in your projects. The included samples all rely on a sample Bot class that extends Agent.

In all examples the bot's login credentials are loaded from the config/config.js file according to environment variables LP_ACCOUNT & LP_USER specifying which account and user's credentials to use.

Global Pre-requisites

  • A LivePerson Account with Messaging
  • A config/config.js file that exports a configuration object (see config/example_config.js)

Description

This is an example of a bot acting as an Agent. It starts in the ONLINE state and subscribes only to updates for its own conversations. It receives new conversations by subscribing to routingTaskNotification events which indicate that new conversations have entered the relevant skill queue and are "ringing" to the bot. The bot consumes these routing events and accepts all incoming conversations, thereby joining with the role ASSIGNED_AGENT.

This bot then takes various actions in response to messages from the visitor:

  • If the visitor says "time" or "date" the bot will respond with the relevant information (local time of bot system)
  • If the visitor says "content" the bot will send a structured content object.
    • Further information about creating valid structured content objects can be found here
  • If the visitor says "transfer" the bot will transfer the conversation to the configured transferSkill.
    • In order for the bot to successfully transfer conversations to a new skill you must set the value of transferSkill in agent.js to a string matching the Skill ID of the target skill. You can obtain your skill ID using the Skills API.
  • If the visitor says "close" the bot will close the conversation
  • Anything else the visitor says the bot will simply repeat back to the visitor prefixed with 'you said '.

Pre-requisites

  • A user with the Agent role
  • (Optional) transferSkill set in agent.js

Running the Agent Example

LP_ACCOUNT=(account name) LP_USER=(login name) node agent.js

This is an example of a bot acting as a Reader. It starts in the AWAY state so that no conversations will "ring" to it, but it subscribes to updates for all conversations on the account. When any new conversation begins the bot adds itself as a participant with the role READER. This role is appropriate for bots which need to see chat lines and and metadata about the consumer and the agent assigned to the conversation (whether human or bot) but do not need to participate in the conversation in any way.

Pre-requisites

  • A user with Agent role and the "Join another agent's conversation" permission

Running the Reader Example

LP_ACCOUNT=(account name) LP_USER=(login name) node reader.js

This is an example of a bot acting as a Manager. It starts in the AWAY state so that no conversations will "ring" to it, but it subscribes to updates for all conversations on the account. When any new conversation begins the bot adds itself as a participant with the role MANAGER. It then sends a message into the conversation stating that it has joined, which both the ASSIGNED_AGENT and the CONSUMER can see.

Pre-requisites

  • A user with the Agent Manager role and the "Join agents' conversations" and "View agents' conversations" permissions

Running the Manager Example

LP_ACCOUNT=(account name) LP_USER=(login name) node manager.js

Running in Heroku

This project is ready to run the Agent sample in Heroku out of the box. Simply deselect the web dyno and select the worker dyno in Heroku's "Resources" tab, and specify the appropriate config vars in Heroku's "Settings" tab:

LP_ACCOUNTID or LP_ACCOUNT // required
LP_USERNAME or LP_USER // required for username/password authentication and OAuth1 authentication
LP_PASSWORD // required for username/password authentication
LP_TOKEN // required for token authentication
LP_USERID // required for token authentication
LP_ASSERTION // required for SAML authentication
LP_APPKEY // required for OAuth1 authentication
LP_SECRET // required for OAuth1 authentication
LP_ACCESSTOKEN // required for OAuth1 authentication
LP_ACCESSTOKENSECRET // required for OAuth1 authentication