📃
NewBot
  • NewBot, what is it?
  • ConverseScript Syntax
    • Variables
    • Arithmetic
    • Boolean
    • Array and object
    • Entering text and output
    • Magic variables
    • Condition
    • Loop
    • Functions
    • The decorators
      • Use @Condition
      • Use @Action
      • Use @Format
      • Use @Intent
      • Use @Event
  • Prebuilt Formats for Widget
    • Quick Replies
    • Multi Cards
    • Articles
    • Form
  • Pre-built function for the widget
    • Request()
    • Map()
    • _ (lodash)
  • Get Started with Framework
    • Install
    • Main Skill
    • Write the conversational script
  • Use NewBot Framework JS
    • Create a skill (more details)
      • Relationship between skills
      • Use the functions of a child competency
      • Conditional
      • Control access to a skill
    • Create a JavaScript function and trigger it in ConverseScript
    • The constants
    • Write formats
      • Write and use multi-formats
      • Share formats
    • Internationalization (i18n)
    • Set up an NLP system
      • Share the NLP system
      • Use DialogFlow
    • Deploy on the browser
    • Run the chatbot on NodeJS
    • Send data when running the chatbot
    • The middlewares
    • Save the user's progress
    • User object
  • Unit Tests
    • Test a scenario
    • Test variables
    • Spy a function
    • Create a mock
    • Test the events
    • Test the actions
Powered by GitBook
On this page
  • With the native NLP
  • On-the-fly training
  • Use the parser

Was this helpful?

  1. Use NewBot Framework JS

Deploy on the browser

The goal is to run the skill directly in the browser to achieve a conversational system

  1. Type npx webpack in the terminal

  2. You find the generated file in dist

  3. Create an index.html file:

<script src="https://unpkg.com/newbot@latest/dist/newbot.min.js"></script>
<script src="path/dist/browser"></script>

<script>
const converse = new NewBot(MainSkill)
converse.exec('Hey', (output, done) => {
    console.log(output)
    done()
})
</script>

MainSkill is a global variable in the generated file.

On browser, setting the user ID as the second parameter of the exec () method is optional

With the native NLP

<script src="https://unpkg.com/newbot@latest/dist/newbot.with-nlp.min.js"></script>
<script src="skill.js"></script> <!-- you skill -->
<div>
    <input type="text" id="text">
    <button id="submit">Ok</button>
    <pre id="result"></pre>
</div>
<script>
    var converse = new NewBot(MainSkill, {
        model: '/model/model.nlp'
    })
    document.getElementById('submit').addEventListener('click', function() {
        var text = document.getElementById('text').value
        var result = document.getElementById('result')
        converse.exec(text, (output, done) => {
            result.innerText = JSON.stringify(output, null, 2)
            done()
        })
    })
</script>
  1. Put the newbot.with-nlp.min.js file

  2. Set the path to model.nlp

NLP in other languages (other than English)

  1. Install dependencies

npm i newbot @nlpjs/lang-fr

  1. Use the modelLangs property

import { NewBot } from 'newbot/bootstrap/browser-with-nlp'
import MainSkill from '<path to your skill>'
import { LangFr } from '@nlpjs/lang-fr'

const converse = new NewBot(MainSkill, {
    model: '/model/model.nlp',
    modelLangs: [LangFr]
})

On-the-fly training

import { NewBot } from 'newbot/bootstrap/browser-with-nlp'
import { train } from 'newbot/packages/train'
import { LangFr } from '@nlpjs/lang-fr'
import MainSkill from '<path to your skill>';

(async function() {
    const converse = new NewBot(MainSkill)
    // second parameter is optional if only english
    const model = await train(converse, [LangFr])
    await converse.setModelNlp(model, [LangFr])
    converse.exec('hey', (output, done) => {
        console.log(output)
        done()
    })
})()

Use a bundler like webpack, parcel, rollup, etc. to read imports and generate a file

Use the parser

If you want to test uncompiled code directly in the browser, integrate the newbot.with-parser.min.js file instead

<script src="https://unpkg.com/newbot@latest/dist/newbot.with-parser.min.js"></script>

<script>
const converse = new NewBot()

converse.code(`
    @Event('start')
    start() {
        > Hello World
    }
`)

converse.exec('Hey', (output, done) => {
    console.log(output)
    done()
})
</script>

Beware, the newbot.with-parser.min.js file is much heavier than thenewbot.min.js file. Prefer the latter if reading uncompiled code is not necessary.

PreviousUse DialogFlowNextRun the chatbot on NodeJS

Last updated 3 years ago

Was this helpful?

Please, follow this tutorial :

Web NLP