diffore
9/29/2017 - 2:25 PM

Slim widget API

/ subscribe for widget events
nanorep.embeddedWidget.on({
  init: function() {
    console.log('widget: "init" phase (before load)');

    // enable output of debug informatio to console
    this.enableLogging();

    // enforce specific domain configuration:
    this.setConfigId('30344634');

    // set initial context
    this.setContext({ demo: 'my', brand: 'unknown' });

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

    // filter search results by specific labels (all specified labels must be present on the answer)
    this.searchByLabels(['32715845', '30840398']);

    // remove search by labels filter
    this.searchByLabels(null);
  },
  load: function() {
    console.log('widget: "load" phase (fully loaded)');

    // set custom params that will be used inside the articles to replace placeholders {{name}}
    this.setCustomParams({ name: 'John', age: 31 });
  },
  ask: function (query) {
    console.log('widget search:', query);
  },
  noResults: function (query) {
    console.log('no results for query:', query)
  },
  searchResults: function (results, query) {
    console.log('search results for query:', results, query);
  },
  escalate: function (channel, answer) {
    console.log('user escalation:', channel, answer);
  },
  feedback: function (feedbackInfo, answer) {
    console.log('user feedback:', feedbackInfo, answer);
  },
  showAnswer: function (answer) {
    console.log('answer shown:', answer);
  },
  toggleAnswer: function (answer, isOpened) {
    console.log('answer toggle state:', answer, isOpened);
  },
  share: function(target, answer) {
    console.log('sharing answer to', target, answer);
  },
  activateWidget: function() {
    console.log('widget activated');
  },
  activateBlockquote: function (blockQuoteText, answerId, searchQuery) {
    console.log('blockquote activated:', blockQuoteText, answerId, searchQuery);
  }
});