Documentation

Do you use documentation to use NewBot Framework

Deploy on the browser

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

  1. Type newbot build in the terminal
  2. You find the generated file in dist/browser
  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. You can run [/ docs / essential / exec] (the scenario with the exec () method)

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/node-nlp@latest/dist/bundle.js"></script>
<script src="https://unpkg.com/newbot@latest/dist/newbot.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. Integrate the https://unpkg.com/node-nlp@latest/dist/bundle.js file to read the NLP system in the browser
  2. Set the path to model.nlp

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.

© 2019 NewBot