Use the functions of a child competency

Let's use the skill of the previous chapter. We add a custom function.

skills/my-skill/my-skill.js

import code from 'my-skill.converse'

export default {
    code,
    functions: {
        hello() {
            return 'Hey'
        }
    }
}

But we can use it in the parent scenario.

main.js

import code from './main.converse'
import mySkill from 'skills/my-skill/my-skill'

export default {
    code,
    skills: {
        mySkill
    }
}

In main.converse, we will then have:

@Event('start')
start() {
    > { mySkill.hello() }
}

As we can see, we use the mySkill object to access functions.

Read directly a function of the conversational script

Without going through the functions property, we can directly read a function from the conversational script of the child skill. Using the code above, we add these instructions to the script:

skills/my-skill/my-skill.converse

askName() {
    > What's your name ?
    Prompt()
    return :text
}

main.converse

@Event('start')
start() {
    name = mySkill.askName()
    > Your name is { name }
}

Last updated