Type: String
Default: 'nr-conversation-tool'
Specify the key that will be used by the component to store its state inside the localStorage
var convTool = new nanorep.sdk.ConversationTool({ storageKey: 'nr-custom-storage-key' }, document.getElementById('example-options-storagekey'));
connectTo(params) : void
Set connection parameters like host, account, kb, apiKey, context and initializedEntities
params: Object |
Plain JavaScript object containing following fields: host* , account* , kb* , apiKey , context , initializedEntities , clientSideEntities . (Items marked with * are mandatory) |
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('example-methods-connectto')); convTool.connectTo({ host: 'AccountName.nanorep.com', account: 'AccountName', kb: 'English', apiKey: 'a4474788-28d3-4be9-9b6d-a3bcd9b8ac4b', context: { endpoint: 'web', another: 'demo' }, initializedEntities: { brand: 'Apple', UserName: 'John' }, clientSideEntities: ['USER_BALANCE', 'VISIT_LOCATION', 'PRIVATE_ENTITY'] });
reset() : void
Resets the component state
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('example-methods-connectto')); convTool.reset();
sendStatement(params) : void
Resets the component state
params: Object (required) |
JavaScript object containing response of the /api/conversation/v1/statement API call. (Note: /api/conversation/v2/statement API endpoint is in introduction phase.) |
options: Object (optional) |
JavaScript object containing display options like showUserMessage (default: false) and showBotResponse (default: true) |
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('demo-container')); // connectTo ... convTool.sendStatement({ statement: 'hey there!' }); convTool.sendStatement({ statement: 'bye-bye!' }, { showUserMessage: true, showBotResponse: true });
setEntityValue(entityName, entityValue) : void
Used to define missing client side entity
entityName: String |
Name of the client side entity that is missing |
entityValue: Object |
JSON Object that represents entity value |
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('demo-container')); convTool.connectTo({ ... clientSideEntities: ['USER_BALANCE', 'VISIT_LOCATION', 'PRIVATE_ENTITY'] }); convTool.on('missingEntity', function(response) { convTool.setEntityValue(entityName, { kind: entityName, type: 'text', value: 'MOCKED VALUE FOR ' + entityName }); });
convTool.on('botResponse', function(query) {})
Called after user asked something inside the widget (search and conversational)
query: String |
Search query |
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('example-methods-connectto')); // connectTo ... convTool.sendStatement({ statement: 'hey there!' }); convTool.sendStatement({ postback: 'ARTICLE:904673272' }); convTool.sendStatement({ any: 'other', field: 'supported' });
convTool.on('missingEntity', function(entityName) {})
Called each time when client side entity value is requested by the backend
entityName: String |
Name of the client side entity that is missing |
var convTool = new nanorep.sdk.ConversationTool(null, document.getElementById('example-methods-connectto')); convTool.connectTo({ ... clientSideEntities: ['USER_BALANCE', 'VISIT_LOCATION', 'PRIVATE_ENTITY'] }); convTool.on('missingEntity', function(entityName) { console.log('Client side entity that is missing:', entityName); });
1. Add script to your page:
<script src="https://<AccountName>.nanorep.co/web/include.js?sdk=conversation-tool"></script>
2. Create empty <div>
:
<div id="demo-container"></div>
3. Initialize component:
var convTool = new nanorep.sdk.ConversationTool({ storageKey: 'nr-conversation-tool' }, document.getElementById('demo-container')); convTool.reset(); convTool.on({ botResponse: function(response) { console.log('Bot Response:', response); }, missingEntity: function(entityName) { convTool.setEntityValue(entityName, { kind: entityName, type: 'text', value: 'Mocked value for ' + entityName }); } }); convTool.connectTo({ host: 'product_demo.nanorep.co', account: 'product_demo', kb: 'Demo_Bot', apiKey: 'a4474788-28d3-4be9-9b6d-a3bcd9b8ac4b', context: { endpoint: 'web', another: 'demo' }, initializedEntities: { brand: 'Apple', UserName: 'John' }, clientSideEntities: ['PRIVATE_ENTITY', 'ANOTHER_DEMO_ENTITY'] });