📃
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
  • What there is to know !
  • Installing NewBot
  • Run
  • Run with the native NLP

Was this helpful?

  1. Use NewBot Framework JS

Run the chatbot on NodeJS

What there is to know !

The execution of the chatbot is done on the built skill. Thus, reading the chapter on running the chatbot is useful for prodution. In development, NewBot CLI is running.

So, when you see the import const mainSkill from './dist/server.js', it means that you have previously done the command newbot build

If you want to build sources only for NodeJS, do npx webpack

Installing NewBot

Let's first install the newbot module with npm install newbot

Run

With NewBot CLI, code execution in the bot folder is hidden. This allows us to stay focused on conversational script design and chatbot skills

But how to execute ourselves, in a browser or server side?

Let's take an example :

const { NewBot } = require('newbot')
// after `newbot build`
const mainSkill from './dist/node/bot'

const converse = new NewBot(mainSkill)
converse.exec('Hey', 'user id', (output, done) => {
    console.log(output)
    done()
})

The user runs the scenario with the exec() method. 1. The first parameter is the incoming message 2. The second parameter is the return function. It is called each time the conversational script sends data.

  • output contains the chatbot message

  • done() is a function to execute to continue the scenario

Run with the native NLP

NodeJS side, you must put the path to the model.nlp file

const { NewBot } = require('newbot')
// after `newbot build`
const mainSkill from './dist/node/bot'

const converse = new NewBot(mainSkill, {
    model: __dirname + '/model/mode.nlp'
})
converse.exec('Hey', 'user id', (output, done) => {
    console.log(output)
    done()
})
PreviousDeploy on the browserNextSend data when running the chatbot

Last updated 3 years ago

Was this helpful?