nanorep.sdk

It is very easy to start using the Web SDK on any webpage. Just include the script with the specified list of components and APIs you want to use, and set the SDK options. Then all exposed components in the namespaces will be available for your use.

Methods

init

init(options) : void

Set

Parameters

options: Object Initialize SDK with options that will be used across all SDK components and APIs. options is a plain object like { host: 'vodafone.nanorep.co', account: 'vodafone', kb: 'English' }

setPredefinedValues

setPredefinedValues(values) : void

Set predefined values which can be used by contact forms to prepopulate field values. values is a plain key-value object like: { subject: 'my predefined subject', name: 'John Predefined', email: 'predefined@example.com' }

Parameters

values: Object Initial values object

addChatProvider

addChatProvider(providerName, providerProto) : void

Add custom chat provider implementation as described here

Parameters

providerName: String Name of chat provider
providerProto: Object Specific chat provider prototype object

getDefaultPageContext

getDefaultPageContext() : Object

Get page context object like: { make: 'phone', model: 'iphone', version: '10.0'}. Empty object in case of no context on page

preprocessInput

preprocessInput(hook) : void

Just like in the widget this method allows to sanitize user input that is being sent to server. Hook function will be invoked for each string entered by user with single argument - string entered by user. (method available at any time)
Example usage: nanorep.sdk.preprocessInput(function(input) { return input.replace(/[0-9]/g, '*') })

Parameters

hook: Function Hook function to sanitize user input

Events

escalate

nanorep.sdk.on('escalate', function(channel, answer) {})

Called when user initiated escalation using channeling buttons

Parameters

channel: Object Channel object
answer: Object Answer object, that was escalated

feedback

nanorep.sdk.on('feedback', function(feedbackInfo, answer) {})

Called after user feedback action. Feedback info object contains something like: { positive: false, type: 4, text: '' }

Parameters

feedbackInfo: Object Object with information about feedback
answer: Object Answer object, that was escalated

showAnswer

nanorep.sdk.on('showAnswer', function(answer) {})

Called when answer becomes visible

Parameters

answer: Object Answer object that has been showed

toggleAnswer

nanorep.sdk.on('toggleAnswer', function(answer, isOpened) {})

Called when answer becomes visible or invisible

Parameters

answer: Object Answer object
isOpened: Boolean New state of answer

activateBlockquote

nanorep.sdk.on('activateBlockquote', function(blockQuoteText, answerId, searchQuery) {})

Called when user clicks on "actionable blockquotes" (Touchpoints → Advanced → Actionable block quotes in answer text)

Parameters

blockQuoteText: String Text of activated blockquote
answerId: String Id of answer
searchQuery: String Search query from query field

Demos

Create demo component to check escalation and feedback events

(open browser console and activate feedback or channel)

// initialize SDK with common parameters
nanorep.sdk.init({
  host: 'nanorep.nanorep.co',
  account: 'nanorep',
  kb: 'English'
});

// set predefined values for contact form
nanorep.sdk.setPredefinedValues({ subject: 'my predefined subject', name: 'John Predefined', email: 'predefined@example.com' });

// add event listeners
nanorep.sdk.on({
  escalate: function (channel, answer) {
    console.log('user escalation:', channel, answer);
  },
  feedback: function (feedbackInfo, answer) {
    console.log('user feedback:', feedbackInfo, answer);
  }
});

// initialize demo component
var articleActions = new nanorep.sdk.ArticleActions({
  articleId: '1009685682',
  feedbackType: 'icons',
  enableFeedback: true,
  enableChanneling: true
}, document.getElementById('example'));
<div id="example"></div>