📃
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
  • getMagicVariable ()
  • setMagicVariable ()
  • getVariable ()
  • setVariable ()
  • saveSession ()
  • retrieveSession ()
  • setLang ()
  • getLang ()
  • toJson ()
  • fromJson ()

Was this helpful?

  1. Use NewBot Framework JS

User object

This is an instance of the User class regarding the current user

getMagicVariable ()

Get the value of a magic variable

Parameter

Type

Description

name

String

Name of the magic variable

Example

const converse = new NewBot()

converse.exec('hey', 'user id', {
    preUser(user) {
        user.getMagicVariable('text') // "hey"
    }
})

setMagicVariable ()

Assign a value to a magic variable

Parameter

Type

Description

name

String

Name of the magic variable

value

Any

Value of the magic variable

Example

const converse = new NewBot()

converse.exec('hey', 'user id', {
    preUser(user) {
        user.setMagicVariable('custom', 'foo')
    }
})

In ConverseScript

@Intent(/hey/i)
hey() {
    > { :custom } // => "foo"
}

getVariable ()

Get the value of a global variable

Parameter

Type

Description

name

String

Name of the global variable

setVariable ()

Assign a value to a global variable

Parameter

Type

Description

name

String

Name of the global variable

value

Any

Value of the global variable

saveSession ()

Save a session

Parameter

Type

Description

session

Object

The properties of the session

retrieveSession ()

Return the saved session

setLang ()

Assign the language of the user

Parameter

Type

Description

lang

String

Language to assign (example: fr_FR, en_EN, etc.)

getLang ()

Retrieves the user's language

toJson ()

Returns all the data of the user in order to save his progress in the script

fromJson ()

Restores the user's progress thanks to the JSON saved by toJson()

Parameter

Type

Description

json

Object

User progress

PreviousSave the user's progressNextTest a scenario

Last updated 3 years ago

Was this helpful?