📃
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 parameters
  • Return a promise
  • API

Was this helpful?

  1. Use NewBot Framework JS

Write formats

A conversation is also accompanied by graphic components. We can create formats with the format property.

In main.js

import code from './main.converse'

export default {
    code,
    formats: {
        smiley(text) {
            return text + ' :)'
        }
    }
}

In ConverseScript, let's use the @Format() decorator

@Event('start')
start() {
    @Format('smiley')
    > Hello
}

The decorator applies to the message to be sent. The result will be Hello :)

With parameters

Here is another example, more in depth:

import code from './main.converse'

export default {
    code,
    formats: {
        buttons(text, params) {
            return {
                buttons: params[0],
                size: params[1],
                text
            }
        }
    }
}

Here is the format

@Event('start')
start() {
    @Format('buttons', [
        {
            title: 'share',
            url: 'my.url.com'
        }
    ], 'medium')
    > Hello
}

At the exit, we will have:

{
    buttons: {
        title: 'share',
        url: 'my.url.com'
    },
    size: 'medium'
    text: 'Hello'
}

We can test it with newbot emulator

Return a promise

A format can return a promise if asynchronous notions are executed

import code from './main.converse'

export default {
    code,
    formats: {
        buttons(text, params) {
            return new Promise(resolve => {
                setTimeout(() => {
                    resolve({
                        buttons: params[0],
                        size: params[1],
                        text
                    })
                }, 2000)
            })
        }
    }
}

API

converse.format(nameFormat, (text, params, data, user) => {

})

Parameter

Type

Description

nameFormat

String

Format name

text

String

Text output

params

Array

Parameter table sent by the decorator @Format()

data

Object

Object sent in the exec() method

user

The user who reads the script

PreviousThe constantsNextWrite and use multi-formats

Last updated 3 years ago

Was this helpful?

User