Create a JavaScript function and trigger it in ConverseScript

Let's use the functions property:

import code from './main.converse'

export default {
    code,
    functions: {
        nameFunctionJs() {

        }
    }
}

The ConverseScript script uses the function:

nameFunctionJs()

If the function has asynchronous values, let's return a promise:

import code from './main.converse'

export default {
    code,
    functions: {
        nameFunctionJs() {
            return new Promise((resolve, reject) => {
                // any code
                resolve()
            })
        }
    }
}

Use ConverseScript parameters

Often, information is essential for the proper functioning of the function. For example, retrieve the user information or retrieve the user collection.

Using a magic variable

The script is as follows:

Property converse

The converse property is an object:

Return of a function

The script is as follows:

Use an object

It is possible to use an object with several functions:

In ConverseScript

With specific parameters:

Create a mock of the function

It is very useful to mock a function. Even though each function can be mocked in each unit test, it is also possible to change the behavior in a global way by associating the mock with a skill, which will be triggered during unit tests.

Last updated

Was this helpful?