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:

Here is the format

At the exit, we will have:

We can test it with newbot emulator

Return a promise

A format can return a promise if asynchronous notions are executed

API

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

Last updated

Was this helpful?